On Change of Composite Address in Dynamics CRM

Title sounds to be updated but here lies the interesting info!!!. While working on my client requirements, i have as such to prompt user for filling up particular field on change of composite address in account entity. Sounds simple and easy right 🙂

In a usual way, I attached an event handler to the composite address field in account entity and starting writing my code and published the scripts. When into actions, when i change/update the composite address attribute my event handler which is registered on composite address doesn’t seems to fire :(. In turn it fires on save of the record, confused and stuck. The task seems to be very simple but I am unable to complete it.

I have used address1_composite(Address 1) wherein it is a collection of attributes like

Capture

address1_line1address1_line2,address1_line3,address1_city,

address1_stateorprovince,address1_postalcode,address1_country

After a while i realized like composite address when updated will map the data to the corresponding fields accordingly.

So thought of trying it in a different approach to complete my task. I tried to attach the event handler for all those attributes of composite field and complete on my task like

While loading the form, I have written small piece of code like

var fields=[“address1_line1″,”address1_line2″,”address1_line3″,”address1_stateorprovince”,

“address1_postalcode”,”address1_country”];

for(var i=0; i<fields.length; i++)

{

Xrm.Page.getAttribute(fields[i]).addOnChange(function() { alert(“Hello” + fields[i]) ;});

}

So when ever we update the composite address, its corresponding attribute event fires and can we append the code as per the requirement in the event handler.

The similar behavior is applied when ever anyone tries to update the address field,

we need to provide values for each of attribute of composite address collection in the plugin either on create/update operation. Hope this helps you 🙂

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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