Skip to main content

Notifications

Service | Customer Service, Contact Center, Fie...
Suggested answer

Form On Load event throwing error on addOnProcessStatusChange method call

(1) ShareShare
ReportReport
Posted on by 2
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. 
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,596 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans