Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composite Fields In MSCRM 2013

I have a question on the subject of composite attributes that I would be grateful if you could help me with. I posted this before on other question blogs but got no response I am satisfied with.

I am writing JavaScript that will update the fields (i.e. address1_line1, address1_line2, address1_line3, address1_city, address1_stateorprovince, address1_postalcode, address1_country) in the composite (address1_composite). When the fields are updated the composite does not seem to update. I have to open the composite and close it again. Is there a way of doing this automatically in JavaScript?

I have tried the following ideas:

Idea 1:

Xrm.Page.data.entity.save();

This is recomended at http://community.dynamics.com/crm/b/magnetismsolutionscrmblog/archive/2013/10/22/working-with-dynamics-crm-2013-composite-fields-fly-out-menu.aspx This is not any good as my customers want to view the composite before saving the page. Also I would not want to save the page for my customers as they do not want this. They would like to decide when to do this themselves.

Idea 2:

Xrm.Page.data.refresh();

This is not really what I wanted as I do not want to refresh the whole page. I just want to refresh the composite. Also it bring up a popup that warns you about not having saved the page which will be annoying for my customers.

Idea 3:

Writing the address from the address lines to the composite. This feels like a nasty hack. There is probably more than one way of doing this. I used the function

Xrm.Page.getAttribute("address1_composite")._attribute.setValueForCompositeField();

I do not like this for the following reasons:

  1. This is a hack as it is not using the system functionality of the done button to write the data.
  2. You do not get the system formatting you get with the done button although this will get done when the form is saved so it is not so bad.
  3. In the future if customers are allowed to add their own composite fields it could cause problems as the field names could be different.
  4. It requires me to write extra code for each form that has a composite which has fields with different schema names. E.g. I have to write different code for forms with ShipTo and BillTo addresses as the code for the account form will not work.

Another idea was to set the focus to the composite field after a change has been made to any of the fields inside the composite.

Xrm.Page.data.entity.attributes.get("address1_composite").controls.get(0).setFocus(); 

This is the best idea so for but it is far from perfect. This forces the user to press the done button and hence the fields will be written. I was hoping for something more automated.

My Question: What would be great is if there was a way to click the composite done button in JavaScript. This would give me the formatting of the done button and the automation I need.

Update - 14/04/2014 Since posting this question I have been in contact with Microsoft and they say there is no supported way of clicking the done button via a program.

like image 811
Oly Avatar asked Feb 11 '14 13:02

Oly


1 Answers

If the field is locked down CRM JavaScript does not send the data back to the server for updating. Another approach would be:

  1. perform the update using JavaScript (so the user sees the change); and
  2. use a server side plugin on the Update event so the value is persisted.
like image 147
Kye Avatar answered Oct 15 '22 19:10

Kye