web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set selected stage of a Business Process Flow?

(1) ShareShare
ReportReport
Posted on by 3,079

I've found how to set the Active stage of a BPF in Javascript - Xrm.Page.data.process.setActiveStage(stageId, callbackFunction);    However, while that changes the Active stage just fine, the "selected" stage (i.e. the one highlighted in colour, etc...) still remains what it was before.  Is there a way to change that in Javascript as well?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Allison,

        You can use the moveNext() or movePrevious() javascript methods to navigate to the next (or previous) BPF stage. Here is a link to the explanations for all the Xrm.Page.data.process methods:

    https://msdn.microsoft.com/en-us/library/dn817878.aspx

    HTH,

    John

  • awalters Profile Picture
    3,079 on at

    Sorry, I should clarify - I'm looking to set a specific stage by ID, as opposed to Next or Previous.  (This is for a button, and so I don't necessarily know which one they're on now.)  Thanks!

  • Community Member Profile Picture
    on at

    Hi Allison,

      I'm not aware of commands in javascript to do what you're asking. Best practices suggests you should only use the Next or Previous methods, and you shouldn't be "jumping" over BPF stages.

    Is there a reason why you don't want to use the navigation for stages? If your button is meant to skip over a BPF stage (I'm making an assumption here), couldn't you use a branching BPF stage and setup logic to have it skip the stage that way instead?

    Please clarify.

    John

  • awalters Profile Picture
    3,079 on at

    The button is meant to run a workflow that creates a related record, and then go to the stage where that data is being presented/worked with.  In every circumstance I can think of, they'd be doing this from the previous stage, but I generally prefer to do things with absolute references instead of relative because I find users have interesting ways of doing things we don't intend.  Since there's a function to set the active stage by ID, I just assumed there'd be a way to set selected as well and just make sure it was always going exactly where I intended it to go.

    Also, moveNext and movePrevious say they can only be used when the active and selected stage is the same, and that seems a difficult thing to guarantee (unless you're using them like it suggests - "For best results, this method should only be used in code that is called in functions initiated by the OnStageChange and OnStageSelected events" - which I can't).

  • awalters Profile Picture
    3,079 on at

    I'll give an example, using in the OOTB functionality I'm sort of trying to mimic.  Say you're on the Lead form, and you've filled in everything required.  The later stages are locked until you qualify the lead, but maybe you want to peek forward at the "Propose" stage, just to see what it entails.  You click it, and "Propose" is currently your selected stage.  Now you hit "Qualify", and it creates an Opportunity, opens the Opportunity, and sets "Develop" as both the active and the selected stage (even though "Qualify" was your active stage and "Propose" was your selected stage.

  • Hasibur Rahman Profile Picture
    on at

    I recently did something like this with Lead

                  string fetchXMLLead =

                                   "<fetch mapping='logical'>" +

                                       "<entity name='lead'>" +

                                           "<attribute name='stageid' />" +

                                           "<attribute name='processid' />" +

                                           "<attribute name='statecode' />" +

                                           "<filter type='and'>" +

                                               "<condition attribute='leadid' operator='eq' value='" + context.PrimaryEntityId.ToString().Replace("}", "").Replace("}", "") + "' />" +

                                           "</filter>" +

                                       "</entity>" +

                                   "</fetch>";

                   EntityCollection entCollectionLead = Service.RetrieveMultiple(new FetchExpression(fetchXMLLead));

                   if (entCollectionLead.Entities.Count > 0)

                   {

                       CurrentLeadRecord = entCollectionLead.Entities[0];

                       string currentLeadRecordStatusValue = ((OptionSetValue)CurrentLeadRecord["statecode"]).Value.ToString();

                       if (currentLeadRecordStatusValue.Equals(StateValueForOpen))

                       {

                           changeStage("Propose");

                       }

                       else

                       {

                           changeStage("Close");

                       }

                   }

  • awalters Profile Picture
    3,079 on at

    What's the changeStage function?  I can't find documentation on it anywhere...

  • Inogic Profile Picture
    713 on at

    Hi Allison

    For ChangeStage  event, You need to bind event handler for BPF stage change. You can bind event on load of CRM entity form. Please follow below link for the same.

    msdn.microsoft.com/.../dn817878.aspx

    Regarding selecting BPF stage make sure mandatory fields for the stage are fulfilled before moving to next stage.

    Thanks

  • awalters Profile Picture
    3,079 on at

    Doesn't binding the event handler add things to do when the stage changes?  I'm trying to trigger the stage change, not add things to it.  (Also, I'm not seeing a function called changeStage on that page anywhere...)

    Hmmm....that being said, I *may* be able to change my logic around and do things when they go to change stages, rather than the other way around.  I'll play.

  • awalters Profile Picture
    3,079 on at

    So I was able to get the workflow to fire when the Next Stage button is pressed.  All good.  However, it can't automatically continue onto the next stage because they have to choose the related record (there should always only be one - I've set up relationships both directions to ensure this stays in effect a 1 -> 1 relationship).  But even if there's only one related record, it makes you select it to move to the next stage of a multi-entity BPF.  That seems to be my final barrier here, if I do it this way instead.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans