Composite Fields In MSCRM 2013
Asked Answered
I

1

10

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.

Impudent answered 11/2, 2014 at 13:3 Comment(5)
I thought I'd comment on this question. I have the same issue (as of 09/04/14 ddmmyy). It looks like the composite attribute update is tied to the action of either confirming or clicking out the fly out edit box. I had expected the composite control to be updated whenever one of the related attributes changed (even with a fireOnChange, not just manually). Usual MS stuff sadly.Moneybag
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. I have added this to the main body of the question above.Impudent
What did you decide on?Indistinguishable
I would guess this one. <br><br> 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.Gearbox
@Impudent let me know, if you haven't found solution yet. I have one.Dialectic
I
1

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.
Indistinguishable answered 18/2, 2015 at 5:52 Comment(2)
Hi there. Thanks for this. However this would have the same problem as Idea 1 above. The customer needs to be able to check the composite before it is saved back to the server.Impudent
In that case you are stuck with bespoke Javascript.Indistinguishable

© 2022 - 2024 — McMap. All rights reserved.