{Power 2021} Get current App details in Model Driven App and D365 client-side scripts

In a recent project there was a need to know Model driven App name in client side script.

We can achieve the requirement using following script.

In this example I have alerted App details on Load of a custom entity titled “Visit” under a Model driven App called “Visitor management”.

Here is the output:

clip_image002

Here is the script:

function onLoadApp()

{
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppProperties().
then(

function successCallback(app)

{
var message = “App Display name: ” + app.displayName + “\nApp name: ” + app.uniqueName + “\nApp Id: ” + app.appId;
var messageString =
{
confirmButtonLabel: “Ok”,
text: message
};

var messageAlertOption =
{
height: 120,
width: 260
};

Xrm.Navigation.openAlertDialog(messageString, messageAlertOption);

},

function errorCallback()

{ console.log(“Error”);

}

);

}

Other details that are accessible in the app object are mentioned below:

· appId

· displayName

· uniqueName

· url

· webResourceId

· webResourceName

· welcomePageId

· welcomePageName

Hope it helps and Power 365ing as usual!

Other ways to learn with me:

clip_image004

Any problem in Power Platform or Dynamics 365 – end user, Microsoft partner or an individual?

Problem Area – Technical, Functional, Training, Development or consulting?

I am here to help, get in touch here: Click here

clip_image006

Advertisement

{Power 2021}Exception handling and notification in Model driven Apps Scripts

Hi All,

In this video supported blog I am going to tell about Exception handling in your scripts in Model driven Apps and how to notify the user in meaningful way.

Here is the code sample used in above video example:

function onLoad(executionContext)
{
try
{
var formContext = executionContext.getFormContext();
formContext.getAttribute(“gendercode1”).setValue(0);
}
catch (exception)
{
var exceptionAlertString =
{
confirmButtonLabel: “Ok”,
text: “On Load error: ” + exception.message
};
var exceptionAlertOption =
{
height: 120,
width: 260
};
Xrm.Navigation.openAlertDialog(exceptionAlertString, exceptionAlertOption);
}
}

Hope it helps and Power 365ing as usual!

Any problem in Power Platform or Dynamics 365 – end user, Microsoft partner or an individual?

Problem Area – Technical, Functional, Training, Development or consulting?

I am here to help, get in touch here: Click here

clip_image007