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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Model-drive app - Type...
Power Apps
Unanswered

Model-drive app - TypeError: Cannot read properties of null

(0) ShareShare
ReportReport
Posted on by 60
Hi,
 
I had a JScript in my solution and the code is:
function viewAuditHistory(executionContext) {
	var formContext = executionContext.getFormContext();
	formContext.ui.headerSection.setCommandBarVisible(false);
	Xrm.Page.ui.navigation.items.get('navAudit').setFocus(true);
}
I set this script in my Model-driven app as On Load Events. However, everytime my user open the error appear:
TypeError: Cannot read properties of null (reading 'setFocus')
    at viewAuditHistory (https://***)
    at b._executeFunctionInternal (https://***)
    at b.execute (https://***)
    at https://***
    at i (https://***)
    at re._executeIndividualEvent (https://***)
    at re._executeEventHandler (https://***)
    at Object.execute (https://***)
    at w._executeSyncAction (https://***)
    at w._executeSync (https://***)

Error Details:
Event Name: onload
Function Name: viewAuditHistory
Web Resource Name: ***
Solution Name: Active
Publisher Name: ***
But I've never had a problem using the app. This issue drove me crazy and appreciate all suggestions!
Categories:
I have the same question (0)
  • SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
    Hi ,
     
     
    The Xrm.Page API is deprecated in the new version of the platform. It’s recommended to use formContext for accessing form-related elements.
    function viewAuditHistory(executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.ui.headerSection.setCommandBarVisible(false);
        var navAudit = formContext.ui.navigation.items.get('navAudit');
        if (navAudit) {
            navAudit.setFocus(true);
        } else {
            console.log("Navigation item 'navAudit' is not available");
        }
    }
     
    pls try.
     
    thanks.
     
     
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard