locked
Refresh CRM2013 composite on form (javascript) RRS feed

  • Question

  • Hi.

    I am currently "moving" some of my code from 2011 to 2013, and I have encountered a "problem".

    I have a script that sets some field values on the form with javascript, but I can not for the life of me get the new composite type to refresh.

    This part of the code is pretty simple, all I want to do is to fill in the address1 fields and refresh the composite.

    Currently I have tried:

            function FillForm(index) {
                var _result = data[index];
                Xrm.Page.getAttribute("name").setValue(_result.Name);
                Xrm.Page.getAttribute("accountnumber").setValue(_result.OrganizationNumber);
                Xrm.Page.getAttribute("address1_line1").setValue(_result.VisitingAddress);
                Xrm.Page.getAttribute("address1_postalcode").setValue(_result.VisitingZipCode);
                Xrm.Page.getAttribute("address1_city").setValue(_result.VisitingCity);
    
                Xrm.Page.getAttribute("address1_line1").setSubmitMode("always");
                Xrm.Page.getAttribute("address1_postalcode").setSubmitMode("always");
                Xrm.Page.getAttribute("address1_city").setSubmitMode("always");
                Xrm.Page.getAttribute("address1_composite").setSubmitMode("always");
    
                Xrm.Page.getAttribute("address1_line1").fireOnChange();
                Xrm.Page.getAttribute("address1_postalcode").fireOnChange();
                Xrm.Page.getAttribute("address1_city").fireOnChange();
                Xrm.Page.getAttribute("address1_composite").fireOnChange();
            }

    But the component will not update with new data. If I click on the component and de-click it, it updates. Or when the autosave/refresh kicks in it refreshes.

    But I would really like to have the composite control to refresh instantly (or instantly when I want).

    And ideas?

    Cheers.


    Thursday, November 14, 2013 9:17 AM

Answers

  • Finally got it. The "correct" method was in the _attribute property:

    Xrm.Page.getAttribute("address1_composite")._attribute.setValueForCompositeField(_result.VisitingAddress + "\r\n" + _result.VisitingCity + " " + _result.VisitingZipCode);

    Only you have to build up you composite your self, but is manageable enough.

     
    • Marked as answer by Gaute Odin Friday, November 15, 2013 12:32 PM
    Friday, November 15, 2013 12:32 PM

All replies

  • Have you tried: Xrm.Page.data.refresh(); or worse case scenario, add Xrm.Page.data.entity.save(); to the end of the method.

    If that fails, you could try adding a switch field to reload the form, or try hiding/showing fields in order to get them to refresh.

    CRM 2013, so far has been hit-and-miss for a lot of us, there are still quite a lot of bugs or features that don't work as expected. This is just one thing I have encountered amongst many. I have an CRM instance in the APAC centres and one in EMEA and I have noticed that APAC instances have solved a lot of the problems I am experiencing in EMEA instances.

    Good luck and please report back if there is a fix so that others know.

    Thursday, November 14, 2013 10:04 AM
  • Hi.

    I have now tried you suggestions:

    - Xrm.Page.data.refresh();

    This trigger a popup/alert saying that changes have not been saved. Ok/Cancel to continue.

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

    This saves the form and displays the correct information.

    So Xrm.Page.data.entity.save(); works best, but you are forced to save the entity to DB. There is no way of reviewing or fill in additional data (required fields not covered with the fillform function would trigger a popup I guess, etc).

    So it does not really cover my needs, but thanks for the suggestions. The composite should have a refresh method of some sort (it does not have, tried it). I have also experimented with the focus function to no avail.

    I really hope this is supported, as it seems it should not be difficult to support. 

    I am gone have a last try, testing some blur functions and see if that works.

    Edit: Tried the blur function (focus composite, then blur composite), but did not work :(

    I am out of ideas, guess we have to hope this function comes in a rollup.

    Edit2: Also tried to hide then show the field, but no dice.




    • Edited by Gaute Odin Thursday, November 14, 2013 10:43 AM
    Thursday, November 14, 2013 10:24 AM
  • Made some headway:

    If I use a method on the object, I am able to change the label of compiste, but not the textfield:

    Xrm.Page.getControl("address1_composite").tryUpdateValueElementText(_result.VisitingAddress + "\r\n" + _result.VisitingCity + " " + _result.VisitingZipCode);

    It does change in real time, but when you focus the composite, the old value shows. (and how supported this is I do not know, as I just inspected the available function on the

    Xrm.Page.getControl("address1_composite");
    object.
    • Edited by Gaute Odin Thursday, November 14, 2013 1:09 PM
    Thursday, November 14, 2013 1:08 PM
  • I'm facing some of these inconsistencies myself - have you tried using Business Rules to copy the changes over instead? I had a similar problem capitalising the Fullname composite field. I managed to overcome by using business rules. One thing I would never suggest is to wait for a rollup - I m still waiting for fixes from CRM 4.0 but they are deemed non-essential.

    Good luck with your endeavour. I'm laughing as I type this because I know your frustrations - but this is a little of what may be ahead of you. 

    Thursday, November 14, 2013 2:15 PM
  • Finally got it. The "correct" method was in the _attribute property:

    Xrm.Page.getAttribute("address1_composite")._attribute.setValueForCompositeField(_result.VisitingAddress + "\r\n" + _result.VisitingCity + " " + _result.VisitingZipCode);

    Only you have to build up you composite your self, but is manageable enough.

     
    • Marked as answer by Gaute Odin Friday, November 15, 2013 12:32 PM
    Friday, November 15, 2013 12:32 PM