PPMRoleClassMapper().validateAccess returns undefined value

ashwinipingle
Tera Guru

Hello Developers,

I was trying the following script in background script

*********************

// Define the user name or some identifier for the user that you want to fetch
var userName = 'MFD Project Reader';

// Create a GlideRecord object for the Sys_User table
var userGR = new GlideRecord('sys_user');
userGR.addQuery('name', userName);
userGR.query();

if (userGR.next()) {
    gs.print('User Found: ' + userGR.getValue('name'));

    // Assuming we need to validate access for the specified user
    var sysClass = 'pm_project'; // System class or table name

    // Call the validateAccess method
    var answer = new PPMRoleClassMapper().validateAccess(userGR, sysClass);

    // Log the result
    gs.print('User: ' + userGR.getValue('first_name'));
    gs.print('User has access to ' + sysClass + ': ' + answer);
} else {
    gs.print('User not found: ' + userName);
}
********************
I get the following result - why do I get a "undefined" result for PPMRoleClassMapper().validateAccess
*** Script: User Found: MFD Project Reader
*** Script: User: MFD
*** Script: User has access to pm_project: undefined
 
1 ACCEPTED SOLUTION

@ashwinipingle 

the correct way to call is this, this worked for me

    var answer = PPMRoleClassMapper.validateAccess(userGR, sysClass);

AnkurBawiskar_0-1738665771191.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@ashwinipingle 

did you check and see what that function actually does?

Seems you are not calling it in correct syntax

 

AnkurBawiskar_0-1738584779030.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@ashwinipingle 

try to call like this, don't give new keyword

var answer = PPMRoleClassMapper().validateAccess(userGR, sysClass);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar I tried your suggestion but no luck yet.

I have created a case to servicenow. I cant debug anymore. I could be having some error in script but better to get response from support.

@ashwinipingle 

yes seems a bug because it should either return true or false

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader