Dynamics CRM Javascript · Dynamics CRM Ribbon Customization · Javascript · Uncategorized

[Step by Step] Dynamics CRM Show Ribbon button on one Model Driven App and Hide same button on other Model Driven App

Today One of my colleague asked “How to Show/Hide ribbon button based on Model Driven APP”. I though of exploring this use case by myself and wanted to share with you.

Dynamics CRM 365 recently release new JavaScript api to get Model Driven App properties which will help us to get App ID and other details. We are going to use App Id to write our logic to either return true or false from Javascript function.

I am going to show Assign button on Account form in Sales Hub and hide same button in Custom Service.

Here are step by step guide to achieve this Business requirement

  1. Create new solution and add Account entity into it.
  2. Create Javascript web resource and add code given in end of the blog. I will explain code in the end.
  3. Open Ribbon workbench and Right click on Assign button from Account form and click on Customize Button
  4. Add Enable rule and call Javascript function
  5. Associate this Enable rule to Comman
  6. Publish the changes and refresh the form on both App and voila!

Javascript Code

function ShowHideRibbonButtonBasedOnModelApp()
	return new Promise(function (resolve, reject) {
	var globalContext = Xrm.Utility.getGlobalContext();
	globalContext.getCurrentAppProperties().then(function (object) 
		var found=false;
		if(object.appId=='89603f8e-0d98-ea11-a811-000d3a0a7553') found=true;//Sales Hub
		else if(object.appId=='2a96fdac-0d98-ea11-a811-000d3a0a7553') found=false;//Custom Service
		else found=true;//other Model Driven Apps
		resolve(found);//promise to retun true or false
	}, function (error) {


Key Points –

  1. We have to use Promise to return the result correctly. Read more about promis in Javscript by Debajit here
  2. getCurrentAppProperties() Api which returns the Model Driven App properties.

Result –

Sales Hub


Custome Service



Hope this helps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s