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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Trying to add a function as an event handler for the OnPreStageChange event but getting error "formContext.data.process.addOnPreStateChange is not a function"

(0) ShareShare
ReportReport
Posted on by 35

Hi Community!

I'm trying to add a function as an event handler for the OnPreStageChange event to check some conditions before a user moves an opportunity from one stage in the business process to another.

Getting the name of the active process is no problem, but using formContext.data.process.addOnPreStateChange to register my function has the error "formContext.data.process.addOnPreStateChange is not a function"

This is my code:

function () {

    function writeToConsole(message)

    {

        if (typeof console != 'undefined') {

            console.log(message);

        }

    }

    // Code to run in the form OnLoad event

    this.formOnLoad = function (executionContext) {

        var formContext = executionContext.getFormContext();

        writeToConsole("Process-Name: " + formContext.data.process.getActiveProcess().getName());   // <= works fine!!!

        formContext.data.process.addOnPreStateChange(   // <= error

                function (executionContext) {

                    // check condition ...

                    writeToConsole("test");

                }       

            );

    }

 }

Thanks in advance for any ideas or help!

Ecki

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    I hope you are using this on Unified interface and not using class web client. Because this method is only supported for UCI.

    docs.microsoft.com/.../addonprestagechange

  • ebecki Profile Picture
    35 on at

    Hi Bipin, thanks for your reply. I created a new Testenvironment on Dynamics 365, so no OnPrem and I think also no chance to get the old UI ;-)

    If I debug my code i can also see the method as a Prototype:

    Screenshot-2022_2D00_06_2D00_03-um-08.47.58.jpg 

    Regards

    Ecki

  • Verified answer
    ebecki Profile Picture
    35 on at

    Hi all, I found my fault  and I can't believe ... it is just a typo :D

    but it took me several hours :(

    it has to be:

    formContext.data.process.addOnPreStageChange

    and not:

    formContext.data.process.addOnPreStateChange

    Thanks and best regards

    Ecki

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 196 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 129

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans