Once an activity is marked as completed in Dynamic 365 CRM, there is no out-of-box way to reopen it.
So here I am outlining a solution that could be used to reopen any close activity.
It involves us to
- A Jscript WebResource
- Creating custom button on specific activity entity
1] Create a Jscript Web resource
function reopenActivity()
{
var activityName =
Xrm.Page.data.entity.getEntityName();
var activityId =
Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
var entity = {};
entity.statuscode = 1;
entity.statecode = 0;
Xrm.WebApi.online.updateRecord(activityName, activityId, entity).then(
function success(result) {
var updatedEntityId = result.id;
Xrm.Page.data.refresh();
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
3] Create a custom button using Ribbon Workbench
Create a button and define its various parameters.
ID : new.synlims_inspection.ReOpenActivity.Button
Tool Tip Description: Re-Open this Activity to be edited.<br/><br/>The activity moves to the open activity views.
Create a command for button and link the Jscript library
created above.
Command ID : new.synlims_inspection.ReOpenActivity.Command
Create a FormStateRule
ID : new.synlims_inspection.ReOpenActivity.EnableRule
2 comments:
Been looking everywhere for a nice simple javascript solution to create a custom "reopen" button. Thanks for that! Worked perfectly for me :)
Great example and just what I was looking for. For future proofing XRM.Page is being deprecated so the code would need to have a parameter for execution context. So the code should be:
function reopenActivity(eContext)
{
var activityName = eContext.data.entity.getEntityName();
var activityId = eContext.data.entity.getId().replace('{', '').replace('}', '');
var entity = {};
entity.statuscode = 1;
entity.statecode = 0;
Xrm.WebApi.online.updateRecord(activityName, activityId, entity).then(
function success(result) {
var updatedEntityId = result.id;
eContext.data.refresh();
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
Then supply a CRM Parameter of "PrimaryControl" on the Command action.
Post a Comment