D365 Quick Tip: Getting layoutXml from DevTools

Most times when you want to use AddCustomView() method to a Dynamics 365 control, you need to pass layoutXml to the method that will show the view you define.
fromCOde

There’s an easier trick than writing this up.

Select your View

Assuming, you have an Advanced Find view open in the window which you want as a layoutXml of, on the same, press F12 to open Dev Tools. Select the selector.
selector

And on the Advanced Find window, select Body section
andSelectBody
Click on it, and the par will be selected in the Console of the Dev Tools.

Once this is available, search for layoutXml and cycle through the results to go to the last result.
selectFromConsole

select the “value” part. That is your layoutXml. Hope this helps.

Use setFormNotification (Client side JS) in D365 v9 while Real-Time workflow is executing

Often, when a real-time workflow is being executed in the background, users don’t know how long it will take for the processing to finish. setFormNotifications in D365 v9 come handy!

Scenario

Here’s how I put my scenario –

  1. I call the Real-Time workflow using JS, example, on change of a certain field or the JS being called from the Ribbon button.
  2. The JS will trigger the Real-Time workflow I have.

Now, while the Real-time workflow is running, the user doesn’t know it has been called and should the user retry the same action? Here’s when the form notification is vital.

While the processing is happening, the message will remain as a notification on the form. Once the processing is complete, the notification will be cleared.

JS Implementation

For the JS code implementation, the function to call the workflow needs ProcessJS which is available on https://github.com/PaulNieuwelaar/

  1. So on the Form, I’ll add my file after ProcessJS file.
    formProperties
  2. Here’s the Account Form code I wrote. I created a JS file to call the Real-Time workflow.
    jsCode
  3. In the above code, the Xrm.Page.ui.setFormNotification(Message, Type of notification, Unique Identifier); This will set the notification.
  4. Page.ui.clearFormNotification(UniqueIdentifier); will clear the notification from screen.
  5. Using this, When the Process enters in Processing mode, the message is shown on screen as “Please wait while processing”
    messageShown
  6. And once the execution is finished successfully, the notification is cleared.
    wfExecuted
    notificationCleared

Similarly, you can even use this approach for WebAPI calls and have clearFormNotification set in the Success/Failure callbacks.

Hope this helps!

Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM

While working with BPF fields using JavaScript, there can be instances where you might want to keep the field locked in a certain stage but unlocked in another stage. And using Xrm.Page.getControl(controlName) or for v9 – getFormContext.getControl(controlName) should differentiate between the 2 fields?

Let’s see what we need to do here.

Scenario

  1. Let’s say I want the users to enter Customer Need data in Develop Stage.
    unlockedField
  2. But, just view what data is present in Propose Stage shown below, not modify it. (I’ve just renamed the field to Summarize Customer Need instead)
    lockedFields

JavaScript Usage to access the Control

  1. Now, since the Summarize Customer Need field is the second time, using getFormContext.getControl(“header_process_customerneed”) will be fetched to disable the first field only i.e. Customer Need in Develop stage.
    unlockedField
  2. To access Summarize Customer Need, you need to append “_1” to the control name for the second occurrence. And _2 and so on for further occurrences.
    Here’s the sample code which I used to access Summarize Customer Need to access the second occurrence of the field and use setDisabled(true) to lock it –
    code3. And that way, you’ll be able to access Summarize Customer Need control and do your desired operation (like even make it hidden or visible depending on your scenario) –
    lockedFields
    Hope this helps!