Friday, August 22, 2025

Read/Get The Dynamics 365 CRM/CE Current App Name Using Java Script

 Below code are used to get the current Dynamics 365 CRM Model Driven App Name.

Xrm.Utility.getGlobalContext().getCurrentAppName().then(

        function (appName) {

        },

        function (error) {

        }

    );


Example:
Read the current Model Driven App Name, If App Name is Sales Hub then Contact entity/table Account Name(lookup) field make the mandatory, otherwise not.

function getCurrentModelDrivenAppName(executionContext)
{
let formContext = executionContext.getFormContext();
Xrm.Utility.getGlobalContext().getCurrentAppName().then(
function (appName)
{
if (appName == "Sales Hub")
 {
   formContext.getAttribute("parentcustomerid").setRequiredLevel("required");
}
else
 {
formContext.getAttribute("parentcustomerid").setRequiredLevel("none");
 }   
},

function (error)
 {
alert("error " + error.message);
});

}


No comments:

Post a Comment

Hide And Show The Dynamics 365 CRM Button Based On Logged In User Security Roles

 In this post I am going to explain how you will hide and show the Ribbon/Command buttons based on logged in user security rule. I have one ...