CRM 2011 JS: Set attribute requirement level using javascript in CRM 2011

This is how to Set attribute requirement level using javascript in CRM 2011

 

Requirement level setting

Xrm.Page.getAttribute("attributename").setRequiredLevel("none");

Xrm.Page.getAttribute("attributename").setRequiredLevel("required");

Xrm.Page.getAttribute("attributename").setRequiredLevel("recommended");