D365 Set status and statusreason from custom ribbon button using JavaScript on UCI
- Javascript webresouce with a function as written below
function ClickCustomButton(primaryControl) {
var formContext = primaryControl;
setStatusStatusReason(formContext, “account”, formContext.data.entity.getId(), 1, 614020000); // these need to be changed as per your context
}function setStatusStatusReason(executionContext, entityLogicalName, recordId, statecode, statuscode) {
var id = recordId.replace(“{“, “”).replace(“}”, “”);
var data = { “statecode”: statecode, “statuscode”: statuscode };Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(
function success(result) { executionContext.data.refresh(true); },
function (error) { executionContext.data.refresh(true); }
);
}
2. Access Scott’s tool Ribbonworkbench plugin from Xrmtoolbox and access Account entity from the solution you intend to apply these changes.
- Add Ribbon button on account form if you don’t have one
- Add Command definition with JavaScript Action
- Select the webresource and function name ‘ClickCustomButton’ from step 1
- Set Crm parameter -> PrimaryControl
Publish! that should do the magic, no more long code as we done in olden days!
To test go to the account form and click the custom button from step 2, upon click it should change the status and status reason of account.
Note: If you don’t know how to add ribbon button on ribbon workbench click this link before jumping to this blog. If you face any status reason transitions error, then go to the status reason field customizations and edit the ‘Status Reason Transitions’ or disable it.
Thank you! for your valuable evaluative knowledge related to CRM. This was really something that you don’t find so easily and when you use these techniques with the Helium CRM you can get your CRM related problem solved in a smoother way
ReplyDelete