Skip to main content

Notifications

Announcements

No record found.

Customer Service forum
Suggested answer

Form On Load event throwing error on addOnProcessStatusChange method call

Posted on by
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. 
Categories:
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 6,037 Moderator 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans