Sometimes we have to show CRM Form by logged user role. The best way to do this is assign form to correct Security role using CRM Custermizations. But sometimes we have to show the correct Form using Javascripts. For that you can use the below code.
Copy the below function to your global/common javascript file
function LoadUserForm(formName)
{
var allForms = Xrm.Page.ui.formSelector.items.get();
if(allForms != null && allForms.length > 1)
{
for(var i = 0; i < allForms.length; i++)
{
var currentName = allForms[i].getLabel().toLowerCase();
if(currentName == formName)
{
Xrm.Page.ui.formSelector.items.get(i).navigate();
break;
}
}
}
}
Then copy below function to all forms in the same entity
function window.onload()
{
var currentUserRole = GetCurrentUserRole();
if(currentUserRole == 'System Administrator')
{
LoadUserForm('SA Form')
}
else if(currentUserRole == 'Sales Manager')
{
LoadUserForm('SM Form')
}
else if(currentUserRole == 'System Operator')
{
LoadUserForm('SO Form')
}
}
No comments:
Post a Comment