简体   繁体   中英

Use client-side script to set Business Process Flow Stage on Opportunity in Dynamics CRM

I'm working in Dynamics CRM 2015 Online and need to apply some conditional rule to the Opportunity when it is first created from a Lead qualification. Under certain conditions we need to automatically advance the Business Process Flow stage to the second stage in the flow. I've already tried this using variations of a plugin on Opportunity Create to set the stage id, but it seems that any value I assign there is ignored when the Opportunity is created from a Lead. Right now I'm trying to fire a javascript function during the Opportunity Form OnLoad event. One catch here is I'm also working against a field that is business required but not filled in when the Opportunity is created from a Lead so I can't do a simple Xrm.Page.data.process.moveNext() in the script. Instead I am updating the Opportunity using the JQuery SDK function updateRecord that is part of the CRM SDK scripts. Here's the important bits of the code:

opp = {
   OpportunityId: oppId,
   StageId: newProcessStageId
}

SDK.JQuery.updateRecord(
   oppId,
   opp,
   "Opportunity",
   function () {
      // success, refresh the form
      Xrm.Page.data.refresh();
   },
   function (error) {
      alert("An error occurred while updating the opportunity: " + error.description);
   }
);

This does work to change the stage, however the problem is on the form the Business Process Flow still shows the first stage as the selected stage, even though it moved the flag indicating the active stage is stage 2, as seen in this screenshot:

在此输入图像描述

After the update, I do a refresh of the form data, but I don't see any way to set the "selected" stage to match the new active stage. I've scoured the SDK docs and searched around but can't find anything that will do this. Any help is much appreciated!

Unrequire the the required field on load in order to change the stage. Then try to move to the next stage.

What if you do a Xrm.Utility.openEntityForm() call instead of a data.refresh? (BTW, I've been trying to find a way to set selected stage in JS for a while as well, and haven't found anything either. I do think if you completely reload the form instead of just the data, though, it should set the selected to the active.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM