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)

Capture value change for a step in business process flow stage

(0) ShareShare
ReportReport
Posted on by 347

I want to move to next stage automatically in a business process flow when a user selects particular value for a step. The below snippet moves the process to the next  stage

function nextStage(){

console.log("moved")

}

parent.Xrm.Page.data.process.moveNext(nextStage())


Now I want this to happen when a value in a step changes For example when user selects "Form submission" for a step called "Request status", i want the process to move to the next stage. How can I capture the action when user selects a value for the "Request status" step?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    nghieppham Profile Picture
    4,755 on at

    Hi Vicky,

    1. You ensure that you add this field to your form (you can set this field invisible)/

    2. Just add OnChange event to this field to set data.process.moveNext(nextStage())

    This event will be called automatically in the step of business process.

    Regards,

  • svignesh Profile Picture
    347 on at

    Hello Pham,

    Thanks, I added a hidden field and attached to on change event and it calls the function.

    But it is throwing the below error

    Refused to set unsafe header "Content-Length"

    However, if i have the console open, it is working as expected

    Any idea of how to handle this?

  • nghieppham Profile Picture
    4,755 on at

    Hi Vicky,

    Please try to set it visible to test first.

    Could you please share all the message that you are facing with and code for reviewing?

  • svignesh Profile Picture
    347 on at

    Hello Pham,

    below is my code

    function nextStage(){

    console.log(" case moved to next stage");

    }

    function caseStatusChange(){

    parent.Xrm.Page.data.process.moveNext(nextStage());

    };

    I have attached caseStatusChange to onchangeevent. It works when I have console open, otherwise it throws the error "Refused to set unsafe header "Content-Length"

  • svignesh Profile Picture
    347 on at

    Hello Pham,

    Can you please provide a sample

    setting to some variable and then call the function?

    var something = parent.Xrm.Page.data.process;

    and then do something.moveNext() ? 

  • nghieppham Profile Picture
    4,755 on at

    Hi Vicky,

    I tested this method and it has been worked for me.

    /// <reference path="XrmPageTemplate.js" />

    function goToNextStage() {

       //Get Actibe Stage of current record

       var activeStage = Xrm.Page.data.process.getActiveStage();

       Xrm.Page.data.process.moveNext(function sucessCallBack(result) {

           alert(result);

       });

    }

    In the case, you should consider, this method is only work if form is not dirtyform status.

    Your form have to be "Unsave Change" status, then it will work, it just my work around for it. In some case, you could also use Xrm.Page.data.process.SetActiveStage method.

    Regards,

  • svignesh Profile Picture
    347 on at

    Hello Pham,

    Thanks for the help

    its says DirtyForm when I select a value that is not default value.

    But when I change the dropdown to default value, its changing the stage

    Any idea of what the error might be?

  • nghieppham Profile Picture
    4,755 on at

    Hi Vicky,

    It is the problem. Because this event just happen when your form is at "Unsave Change".

    In this case, you maybe optimize your code. You can settime out and then recall the movenext method.

    Regards,

  • svignesh Profile Picture
    347 on at

    Yes Pham,

    I tried a setTimeout of 1000ms but it is not saving the form.

    Is there a way to save the form using XRM?

    its working when I goto next stage, come back to this stage and change the value

  • svignesh Profile Picture
    347 on at

    Thanks for the help Pham

    I am able to get it working, below is the code

    function caseStatusChange(){
    parent.Xrm.Page.data.entity.save();
    setTimeout(function(){
    try{
    console.log("trying to change");
     var activeStage = Xrm.Page.data.process.getActiveStage();
       Xrm.Page.data.process.moveNext(function sucessCallBack(result) {
           console.log(result);
       });
    }
    catch(ex){
    console.log("error in stage movement");
    }
    },1000);
    
    };
    


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