Clear replacement parameter when field is Cleared

One of the issues what I have observed in the last couple of versions of USD is, It’s inability in refreshing the replacement parameters if the field value is removed.

For eg: I have removed a phone number and saved the form, you will still see the old value in replacement parameters of your entity. It works great if you add/modify a field value though. This causes severe issues if we have used these replacement parameters in any of the conditions.

Here is a quick and simple solution to the problem.

I’m considering Account form and telephone1 field for this demo (Extend it further as per your need).
  1. Create an action call with the following information.
Field Name Field Value
Name Some meaning full name
Hosted Control Account
Action RunXrmCommand
Data

function FireScanForDataParameters()

{

var telephone = Xrm.Page.getAttribute("telephone1").getValue();

if(telephone==null || telephone=="")

window.open("http://uii/account/ScanForDataParameters");

}

Xrm.Page.data.entity.addOnSave(FireScanForDataParameters);

Let me take a quick moment to see what we are doing here – We are attaching a function to Onsave, which will check for telephone field value and fires a UII action “ScanForDataParemeters” on Account entity if the value is empty. Watch carefully the URL I’m opening http://uii/account/ScanForDataParameters.

The account in the URL is not really the entity logical name rather it should be the Hosted Control name. (for ex: If my account hosted control name is “Session App Account” then the url would be “http://uii/session app account/ScanForDataParameters”)

Attach the action call to “BrowserDocumentComplete” event of the Account hosted control and you are all good to test.

Reopen your USD (if you already opened it), Open an Account and remove the Telephone field value and Save the form. Your replacement parameters should not contain telephone1 field as shown below…

Before After
Replacement Parameter value before Clearing the value Replacement paramter

Hope you got what you are looking for, Let me know if it is not (via comments) :). All the best, happy coding !!

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 )

Google+ photo

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

Connecting to %s