Refresh CRM 2013 Form using script

Sometimes we have to refresh CRM form using script. Till 2011 following script used to work fine:

window.location.reload(true);

But the following code was not working fine when we wanted to reload the page during save so we implemented following way:

A note here on successcallback and errorcallback methods can be found here:http://thedynamicscrmblog.wordpress.com/2013/12/04/crm-2013-client-api-save-refresh/

Xrm.Page.data.save().then(successCallback, errorCallback);

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

funtction successCallback()

{

//Needed to set form dirty to false explicitly as it is not done by platform

Xrm.Page.data.setFormDirty(false);
var Id = Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(“opportunity”, Id);

}

function errorCallback(attr1,attr2)

{

}

Hope it helps!


Check this out

Trying to Learn Dynamics CRM: Download!

Learn Dynamics CRM App on Google Play store

Advertisement

Lock CRM 2013 Form using script along with locked panel in footer

We had a requirement to lock CRM 2013 form on some condition and it should appear locked.We implemented following code to achieve

the same.(Mix of supported and unsupported scripting)

Below are functions to lock field:

function disableFields(flag) {

    Xrm.Page.ui.controls.forEach(function (control, index) {
        if (doesControlHaveAttribute(control)) {
            control.setDisabled(flag);
        }
    });
}

function doesControlHaveAttribute(control) {
    var controlType = control.getControlType();
    return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;
}

Function needs to be called as below to disable form:

//Code to disable fields
disableFields(true);

$(“#footer_statecode”).find(“span”).each(
function () {
    var sval = $(this).text();
    if (sval == ‘Open’) {
        $(this).text(“Locked”);
    }
}
);
$(“#savefooter_statuscontrol”).hide();

This will disable CRM 2013 form like mentioned below:

image

Notice in the above image that there is a lock panel visible below the form.

Following code to enable form fields back:

//Code to enable fields
disableFields(false);

$(“#footer_statecode”).find(“span”).each(
function () {
    var sval = $(this).text();
    if (sval == ‘Locked’) {
        $(this).text(“Open”);
    }
}
);
$(“#savefooter_statuscontrol”).show();

Hope it helps!