Thursday 24 May 2012

how to reload a page

On entity form load i am showing a user dialog to select some values, and on completion of that dialog I am trying user to see the selection he made on the dialog are reflected on the entity form.

as there is no changes done on any attriubte using javascript, calling Xrm.Page.data.entity.save() is not gonna work.

Tried using Xrm.Page.getAttribute("new_attribute1").setValue(Xrm.Page.getAttribute("new_attribute1").getValue());
 Xrm.Page.getAttribute("new_attribute1").setSubmitMode("always");

The above couple of code lines will not work either, the reason is that though I am trying to use setSubmitMode("always"), still the data entity is not dirty,

so here is code i used make sure the page is reload by force, this following code is already with in many conditions so this code is reached when I need to reload page.

In my understanding setSubmitMode("always") is used to save a value of read only fields, or when we are making some changes on attribute and like to force entity to save.



        if (Xrm.Page.data.entity.getIsDirty()) {

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

        } else {

            window.location.reload(true);

        }




/////////////////
in another scenario I wanted to save some of the values which i calculated using javascript, when there were some mandatory fields on the form are not populated and we don't like use at that moment of time to save values.




function ClearRequiredFields () {
        if (!Xrm.Page.data && !Xrm.Page.data.entity) {
            return;
        }
        var attributes = Xrm.Page.data.entity.attributes.get();
        for (var i in attributes) {
            var attribute = Xrm.Page.getAttribute(attributes[i].getName());
            if (attribute.getRequiredLevel() == "required" && !attribute.getValue()) {
                attribute.setRequiredLevel("none");
            }
        }
    }

No comments:

Post a Comment