Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Business process flow using javascript?

(0) ShareShare
ReportReport
Posted on by 5

I am tracking the stages of Business process flow and setting the field values,

convert this to Form context format;

function formonload() { 


Xrm.Page.data.process.addOnStageChange(getStage);  // Trigger the function when move to next stage.


getStage();
}
function getStage() {


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


var stagename = activeStage.getName();


switch (stagename) {


case "Stage1": // Stage of business process flow
Xrm.Page.getAttribute("field_1").setValue(1);
break;


case "Stage2": //Stage of business process flow
Xrm.Page.getAttribute("field_1").setValue(2);
break;
default:

}
}

  • Dynamic fresher Profile Picture
    5 on at
    RE: Business process flow using javascript?

    ok thank you all!!

  • Community Member Profile Picture
    on at
    RE: Business process flow using javascript?

    Hi,

    Make sure whatever fields you are created all those field must be available on your form.

    And whatever field value or schema you are using in js those fields must be present on the form.

    ERRO: Read properties undefine, generally comes once you are trying to do operation on particular filed but that filed is not present on form. 

    Still if you getting issue please follow the blog you can figure out what you r missing out

    juniorcrmblog.blogspot.com/

    www.youtube.com/.../videos

    Thanks,

    Arshad

  • Dynamic fresher Profile Picture
    5 on at
    RE: Business process flow using javascript?

    This is my code:

    function OnloadofForm(e) {
    try {
    var fContext = e.getFormContext();
    fContext.data.process.addOnStageChange(function () {
    BusinessProcessFlowScript(fContext);
    });
    } catch (ex) {
    Xrm.Navigation.openAlertDialog(ex.message);
    }
    }
    function BusinessProcessFlowScript(fContext) {
    debugger;
    try {

    var activeStage = fContext.data.process.getActiveStage();
    if (activeStage !== null && typeof (activeStage) !== "undefined") {
    var stageName = activeStage._stageStep.description;
    switch (stageName) {
    case "Research":
    if (fContext.getAttribute("resolution").getValue != 1)
    fContext.getAttribute("resolution").setValue(1);
    break;
    case "Resolve":
    fContext.getAttribute("resolution").setValue(2);
    break;
    default:
    }
    }
    } catch (ex) {
    Xrm.Navigation.openAlertDialog(ex.message);
    }
    }

    what is error in here?

  • Pulkit Srivastava Profile Picture
    170 on at
    RE: Business process flow using javascript?

    Hi,

    Please use the code that I have sent, or you can share your code.

    Thanks

  • Dynamic fresher Profile Picture
    5 on at
    RE: Business process flow using javascript?

    This is the error

    pastedimage1647568700152v1.png

  • Pulkit Srivastava Profile Picture
    170 on at
    RE: Business process flow using javascript?

    Hi

    Please share the error log.

    Thanks

  • Dynamic fresher Profile Picture
    5 on at
    RE: Business process flow using javascript?

    sorry, but i am getting same error . i am saving Function "OnloadForm" on the onload event of form but still what is wrong i dont know.

  • Pulkit Srivastava Profile Picture
    170 on at
    RE: Business process flow using javascript?

    Hi,

    this is working code

    function OnloadOfForm(executionContext) {
        try {
            var formContext = executionContext.getFormContext();
            formContext.data.process.addOnStageChange(function () {
                BusinessProcessFlowScript(formContext);
            });
        } catch (ex) {
            Xrm.Navigation.openAlertDialog(ex.message);
        }
    }
    
    function BusinessProcessFlowScript(formContext) {
        try {
            var activeStage = formContext.data.process.getActiveStage();
            if (activeStage !== null && typeof (activeStage) !== "undefined") {
                var stageName = activeStage._stageStep.description;
                switch (stageName) {
                    case "Stage1":
                        formContext.getAttribute("field_1").setValue(1);
                        break;
                    case "Stage2":
                        formContext.getAttribute("field_2").setValue(2);
                        break;
                    default:
                }
            }
        } catch (ex) {
            Xrm.Navigation.openAlertDialog(ex.message);
        }
    }

    If this works for you then please mark as verified 

  • Dynamic fresher Profile Picture
    5 on at
    RE: Business process flow using javascript?

    i am using the above code and i am getting error as:

    pastedimage1647504644307v1.png

  • Pulkit Srivastava Profile Picture
    170 on at
    RE: Business process flow using javascript?

    yes

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans