Scratching your head over why your custom ribbon buttons are not visible or not working as expected–The wonderful Command checker tool from Microsoft might just save your day.

If you have ever worked in Dynamics 365 implementation then it is almost certain that you must have played around with ribbons. And more often than not you must have faced scenario where you have multiple enable and display rules on the form and not sure why the ribbon button is showing up on the form when it is supposed not to show up or vice versa.

And what we do to resolve it. Well, we play around with the ribbon customizations which takes much more time than other customizations in Dynamics 365. And if it is some custom rule, we would attach debuggers to our custom code and debug and find what is going wrong.

What if I tell you that Microsoft just released something which shall help you identify which of your ribbon rule is evaluating to what in a matter of few mins so that you can pin-point to the exact rule which is the culprit. Ta-da! Introducing to you the new Command Checker from Microsoft. You can find the details about the release right here.

In this blog I shall show you some scenarios.

So let’s take a simple example here. I have inserted one custom button called – “Command Checker Test” on the Contact form.

I basically have two rules for the custom button.

1. One display rule – CommandClientTypeRule to show it only on Modern interface.

image

2. A custom rule where I am returning true or false based on some business logic.

image

It’s the most complex logic I could have thought of in the Cornona Lockdown and don’t beat me up for this. Smile

function showHideCommandChecker(fc) {
     // sample code.
     var jobTitle = fc.getAttribute(“jobtitle”);


    if (jobTitle.getValue() !== null) {
         return true;
     }


    return false;
}

And now comes the grand entrance of the “Command Checker”. I open up a contact record. My button is right there. But wait where is the command checker. It ain’t there?

image

It’s a magic wand. You just don’t get it. You have to conjure it up. And the way to do it is just by appending a query string parameter “ribbondebug=true” to the URL of the entity record

image

And now you see the command checker tool. If you don’t see it, it might be hidden under your ellipsis area like in mine case too.

image

What happens when we click it? Magic!

image

You have all your ribbons buttons with their command and actions. Let’ select our Command Checker button.

If I check the command properties, I can see which rules evaluated to true or false so that you can identify why the button is being shown or rather not being shown.

image

As you can see from the above screenshot, we can see the enable rule and the display rule being both evaluated to true. Wonderful isn’t it? We know exactly which rule evaluated to what.

Not only that, when we have multiple solutions installed, we can even see which solution is in effect by viewing the rule definition and solution layers.

I will leave it here and you can explore more detail in the Microsoft link here which is mentioned above as well. And guess what, I just loved exploring it while I was penning this blog down.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Clicking on Lookup value navigating you to a different page. Well no more! Control this behavior with the new addOnLookupTagClick function in 2020 Release preview 1

 

With every release of Dynamics 365, there is something always new for developers. In my last blog I explained about the enhancement in Xrm.WebApi.navigateTo method. Today we will discuss in detail about the new “addOnLookupTagClick” method introduced in Release wave 1, 2020.

So what does this function do? Actually it solves a long standing problem where clicking on a lookup value, it redirected to the lookup record form. A potential problem with this is the user would lose context of the record they are working on. But now this can be avoided. So let’s see how we can achieve the same.

For this demo I use the Account form, Parent Account (parentaccountid) field.

In the onload of the Account form, I add the below code.

Xrm.Page.getControl('parentcustomerid').addOnLookupTagClick(function(e){ 
e.getEventArgs().preventDefault(); // disable the default behavior which to open the lookup record. 
// get the lookup record value 
var lookupRecord = e.getEventArgs().getTagValue(); 
// get formContext 
var fc = e.getFormContext(); 
});

The two most important part of the code are already highlighted inside the function with comments. The first one is to prevent the default behavior which is navigating to the lookup record.

The next one is even more important which allows you to select the lookup record clicked. I used the developer tools to show you the format of data returned by function.

The final line of code is to get the form context.

So what actually we can achieve with this. Well a lot. You can open up the lookup record form in a dialog as I explained in my previous blog.

Or may be you can open up a webresource to show up anything. I mean anything that your customer need to want.

Debajit Dutta

(Dynamics MVP)

For consultation/ training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

 
 

{Quick tip} Show a modal record in specific form in Dynamics 365 model driven app using Xrm.Navigate.navigateTo

With PowerApps release wave 1 2020, Microsoft have released quite a few features under the hood. While some  have hogged the limelight, others continue to evolve in the platform like hidden gems. And one of them is the enhancement in much loved Xrm.Navigate.navigateTo API.

Now with this API you can open an entity record modal and that too with the choice of form you want.

While this blog teaches you on how to do all this using sample code, this kind of feature is actually going to save you loads of time. Imagine you wanted to show specific record form as modal while working on something else. And previously you would require to develop a HTML web resource and map the values back to D365 record. Now you can just use few lines of code to do the same.

Below the sample code piece to open a contact record. Please note as of the current version, only form of type Edit is supported.

Xrm.Navigation.navigateTo({
pageType: “entityrecord”,
entityName: “<put your entity logical name here>”,
formType: 2, // you can only open a form in edit mode as of now. Other form types are not supported.
entityId: <put your record id here>
}, {
target: 2,
position: 1,
width: 700,

       height:600
});

And below is what you see.

image

Awesome isn’t it? Now one problem here is the record will open on the default form. What if you want to open the record in a form of your choice. Well here you go.

Xrm.Navigation.navigateTo({
pageType: “entityrecord”,
entityName: “<put your entity logical name here>”,
formType: 2, // you can only open a form in edit mode as of now. Other form types are not supported.

    formId: “<put your formid here>>”
entityId: <put your record id here>
}, {
target: 2,
position: 1,
width: 700,

       height:600
});

I wrote some code to open it in Information form as you can see below, it did just that

image

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

{Quick tip} Save a record in PowerApps portals using custom button on Entity Form

Recently I had a requirement where my customer asked me to put an additional button on the Edit page of a account form that will perform a set of operations before saving the record.

They didn’t want to tamper the OOB functionality of Submit button that comes with the portal. So basically on Account edit form, you should have two buttons, one OOB submit button and other the custom button – “Validate & Save”.

image

On click of Save & Validate, some custom validations shall be performed and then the record should save with the same behavior of click of Submit button.

So there has two steps to it.

Step 1 : Create the button

Trust me this one is easy with a little bit of DOM element modification. In the Custom Javascript box of the content web page of Entity form, paste the below script.

$(document).ready(function () {

$("div.actions").append("<input type=’button’ id=’btnSaveValidate’ name=btnSaveValidate’ value=’Save &amp; Validate’ class=’submit-btn btn btn-primary form-action-container-left’ />");

});

And the button would appear.Basically the submit button is inside a div element with class = “actions”. With a future release of the portal this may change. all you need to find the appropriate place to put in the button

Step 2 : Save the Record on Click of the button

The usual thought that comes to mind is we will submit the form. Something like this should work

document.forms[0].submit();

But unfortunately it does not work out. This is because saving the record is being handled by server side event handler of the OOB Submit button. So basically you need to mimic the call of the submit button.

And the below code does just that.

$("#btnSaveValidate").bind("click", function () {

// perform your own logic here.

WebForm_DoPostBackWithOptions

(new WebForm_PostBackOptions($(this).prev().attr("name"), ”, true, ”, ”, false, true));

});

All I need is to pass the name of the Submit button in the WebForm_PostBackOptions and this is achieved by using $(this).prev().attr(“name”). And now the server side event handler for the Submit button is called and the record is saved.

And now you are all set and running. You might think why not trigger the client click of Submit button. Well this can be done off course. But then you execute the client side logic if any of the submit button. Our intention was to put custom client side validation and then invoke the server side handler to save the record.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

“Change in Default Search behavior in Dynamics 365 in release wave 1”–Inform your customers before it takes them by surprise.

Well this one came as pure surprise and I got to know of this one only after one of our customer enabled 2020 Release wave 1 feature in one of their SandBox environments and updated us that search on entity grids is not working as excepted.

Let me explain the scenario here. My customer was searching in the opportunities grid and the view that he was currently  in was “Open Opportunities”. Can’t use my customer environment for this blog. Hence using the screenshots of a vanilla environment with Release Wave 1 2020 enabled.

image

If I search on this view with the word Kitchen, our expectation is Dynamics would use the Quick find view to identify all the records matching with kitchen and show the results. But surprisingly it didn’t happen.

image

However in the list of all opportunities, there is indeed an opportunity with topic “Kitchen appliances”. And as per the quick find view configuration of opportunity it is supposed to return that.

image

This one took us completely by surprise. Personally I had no clue of what was happening. The only difference we could make was this started happening after we enabled Release Wave 1 2020 in their SandBox environment. And for the customer it’s a feature they are so accustomed to and suddenly not working.

So we started digging the release notes and we finally found the hidden gem. You can read it here.

image

To be honest, it didn’t go well with my customer but I would keep that aside and jump more into the technical side of it.

Question 1 – “What is happening now by default?”

Well by default, Dynamics 365 or CDS searches in the view that you are in. If you observe carefully, the search textbox now contains a placeholder text – “Search this view”

Question 2 – Can I go back to the previous behavior – Searching based on Quick Find view?

Fortunately, the answer is Yes. You would need to go Settings –> Administration –> System settings and set the value below setting value to yes.

image

Question 3What happens to Categorized/Global search?

The categorized search still used the Quick find view.

What’s my opinion on this feature? It’s a long awaited feature and Microsoft did a great job implementing the same. However would have been better if they hadn’t made it the default behavior in entity searches. This can take your customers by surprise.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Quick tip – Resetting controls inside Gallery in Canvas App

Lately designing quite a few canvas apps for specific modules and this is one issue we faced recently while working for a customer.

So the customer had a gallery control which was bound to CDS contacts and then there were some additional controls like Checkbox, Text inputs etc for each gallery item where end-users can make their choices.

While the actual screen looked much different, this is the mockup I came up for this scenario.

image

They wanted a reset functionality i,e when the reset button is clicked, the controls inside the gallery should be set back to their default  values. In other words in the example here the text inputs should be cleared and checkboxes should be unchecked.

Piece of cake we thought and out in the code on click of the Reset button

image

Well it didn’t work. And then tried something more stupid

image

Quite obvious, it won’t work. But why? A bit of search but this Microsoft Documentation just helped our understanding. This documentation on PowerApps Reset function is just what we we needed. If you go to the link, you would find this statement – “You cannot reset controls that are within a Gallery or Edit form control from outside those controls. You can reset controls from formulas on controls within the same gallery or form”

Quite obvious, the Reset button was outside the gallery and hence invoking Reset from there didn’t work. But is there a way out? Off-course there is one certainly and much easier than you may think.

So let’s first focus on the text input control inside the gallery item. There is a “Reset” property of the input item.

image

We are going to set it to a context variable however you can use App level variable as well which can be set using “Set” function.

image

You may get an error. that’s fine. This is because we haven’t yet declared the context variable.

Now on-select of the button you can write the below code.

image

Quite understandably, ResetTextInput when set to True, it would reset the text input to it’s default value. However you may ask the question – Why are we setting it to false? The reason for this is for the next operation when you click on the Reset button, it will again change the value from Context variable from false to true. Once a value change is detected by the framework, the Reset function would fire again.

If we don’t set to it to false post reset, it won’t work.

The same you can do for your checkbox. You can use the same variable or a different variable.

A simple one but can save you some time if you are not aware of it.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Unable to show rating control on PowerApps portal web page? May be you are missing some steps which portal expect.

Recently we had this scenario where my customer was trying to configure ratings for a web page in PowerApps portal. Basically it’s a page where customers could login and rate the page content.

So here was the developer who created the web-page and also checked the box “Enable ratings”

image

image

As it occurred, everything should work fine. After all the documentation also mentions that all we need to do is to enable the ratings for the webpage. However the rating control was not visible on the web-page. Seemed like a cache issue and even after restarting the portal, it didn’t show up.

So if you wondering why this happens and kind of stuck, this blog will help you out. To basically show the rating on the page, you need to perform two steps:

Step 1: Enable rating on the content page

For every language a content child page is created for web page in the portal. You would find it in the localized content section of the portal.

 image

You would need to open up the page for the specific language and enable ratings for the same.

image

image

Step 2 – Choose the right page template

Now this one can be really hard. Here we have used the Page template provided by the portal which “Page” template. It is to be noted that to show up the ratings control on the web-page, the Page template should be of type Re-write and it should point to ~/Pages/Page.aspx.

image

This can be hard to understand for consultants starting with online portal offering. But for consultants who have past experience of working with ADX controls, there used to be a UserControl called “MultiRatingControl” which we could included in any custom page we develop during those days. The Page.aspx still contains the user control and hence when we use re-write to the specified Page, the rating control shows up.

Old ADX documentation for reference – https://community.adxstudio.com/products/adxstudio-portals/documentation/developers-guide/web-controls/ratings-control/

Hope this helps and save you some time.

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)