This one’s pretty useful when you’re building out URLs in your JavaScript and you are using the AppId of your model-driven Power App / Dynamics 365. You don’t ever want to hardcode these values, and you will need to move your code across your environments at some point so getting this value programmatically is the best approach.
If you prefer to watch a video on this, check out the video on my YouTube Channel:
In the account page below, we see in the URL the AppId of our App – 0da29984-d407-ea11-a81e-000d3a35b116:
Now, let’s go into debug in the browser and run the code below (of course, you can run this anywhere you need to):
var globalContext = Xrm.Utility.getGlobalContext(); globalContext.getCurrentAppProperties().then( function success(app) { console.log(app); }, function errorCallback() { console.log("Error"); });
When we run this, we see in passing a variable into the first parameter (appId), it gives us several pieces of information, including the appId, displayName, uniqueName, url, webResourceId, webResourceName, welcomePageId and welcomePageName:
That’s it. Use any field you want, e.g. app.appId:
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
Hi,
I want to use the app.appId value in a variable. How would I do that?
Hi, thanks for sharing.
I’m looking to an odd question from the users after a release (from classic to the new UUIU).
Two different users, looking at the same entity view page.
Both contains different URLs and one thing in particular that I noticed is one contains
…?appid=…
And another contains
…?app=
How can that be?
My initial thought is due to permissions (limited and the other is a super user).
But now reading this, I’m not so sure.
Hi Carl,
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppProperties().then(
function success(app) { console.log(app); }, function errorCallback() { console.log(“Error”); });
I am using same as above in the console and getting below result
Promise {: undefined}[[Prototype]]:
Promise[[PromiseState]]: “fulfilled”
[[PromiseResult]]: undefined
Hi Carl,
I written script for getting app name, but getting app name is “Undefined”
var appName;
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppProperties().then(
function success(app) {
appName = app.displayName;
},
function errorCallback() {
console.log(“Error”);
});