Hello All,
An interesting request came from customer to find a way that how many times a record has been updated after creation and if Plug-in can be avoided.
I just implemented the request with small JavaScript.
Here is the code that you have write on the load of the form:
updatecounter is the function that determines if the Form is Create Mode or Update mode and then set the value to a custom field in the form called "Counter".
Javascript Function:
function updatecounter()
{
var FormType = Xrm.Page.ui.getFormType();
var count = Xrm.Page.getAttribute("Replace_with_Your_Field_Name").getValue();
if (FormType == 1) // Checks if the form is in create mode
{
Xrm.Page.getAttribute("Replace_with_Your_Field_Name").setValue('0'); // Sets the value of the field to 0
Xrm.Page.getAttribute("Replace_with_Your_Field_Name").setSubmitMode("always"); // Force submit as field is read only.
}
if (FormType == 2 && Xrm.Page.data.entity.getIsDirty()) // Checks if the form is in update mode and if anything changed in the form.
{
count = parseInt(count)+1;
count = count.toString();
Xrm.Page.getAttribute("Replace_with_Your_Field_Name").setValue(count);
Xrm.Page.getAttribute("Replace_with_Your_Field_Name").setSubmitMode("always");
}
}
Save the customization and Publish.
This is pretty much it is.
Result :
Thank You at looking at my post.




No comments:
Post a Comment