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

Announcements

News and Announcements icon
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 Moderator on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 25

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 23 Most Valuable Professional

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 16

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans