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

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested answer

Form On Load event throwing error on addOnProcessStatusChange method call

(2) ShareShare
ReportReport
Posted on by 4
I have added the following JavaScript to a Case form to launch the resolve case dialog when a user completes the last step of the business process flow:
 
function onLoad(executionContext) {
    var formContext = executionContext.getFormContext();
    formContext.data.process.addOnProcessStatusChange(onFinishBPF);    
}
 
function onFinishBPF(executionContext){
    var formContext = executionContext.getFormContext();
    var status = formContext.data.process.getStatus();
    if (status === "finished") {
        CrmService.IncidentRibbon.CommandBarActions.resolve();
    }
}
 
Very infrequently, we get this script error when a user opens the form:
 
Cannot read properties of null (reading 'setValue')
Event Name: onload
Function Name: onLoad
 
Unfortunately it happens infrequently enough that I haven't been able to replicate it while debugging to identify where the error is occurring. So I'm not sure if the problem is with executionContext being null or a problem with calling the addOnProcessStatusChange() method. Since it only happens occasionally, I suspect that sometimes the onLoad function is getting called before everything is actually completed loading.  
 
 
 
I DO have the "Pass execution context as first parameter" option selected in the event configuration.
 
Any suggestions would be greatly appreciated. 
I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    Form On Load event throwing error on addOnProcessStatusChange method call
    Hello User,
     
    You can add some delay..so that your script can run once the form is loaded.
     
    Thank you,
    Amit Katariya

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 60

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 16 Super User 2025 Season 2

#2
CU29080825-0 Profile Picture

CU29080825-0 16

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans