D365 Set status and statusreason from custom ribbon button using JavaScript on UCI

Sabjan SamaDyn365CE4 years ago15 Views

We have seen including myself this request quite a lot from early days on CRM 2011 ‘Set Status, Statusreason by clicking the ribbon button’. I started to love the new way of getting this done so quickly in latest UCI by just calling the Xrm.WebApi.updateRecord function to update the record. All we need before start is JavaScript Webresource, Ribbon button on the entity form. See below scenario to click a custom button on Account form to change the status and status reason and refresh the form.

  1. 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.

 

Original Post https://mscrmsama.wordpress.com/2020/03/25/d365-set-status-and-statusreason-from-custom-ribbon-button-using-javascript-on-uci/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...