Skip to main content

Notifications

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

Form On Load event throwing error on addOnProcessStatusChange method call

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 7,797 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

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,912 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,355 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans