Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

ashwinipingle
Tera Guru

@Ankur Bawiskar   I am calling the function correctly since it has 2 arguments - user and sysclass/table.

The function is doing what you have provided in your response.

I expect the function to pass value true or false when user is any user from my instance and table is 'pm_project'.

However I am getting an answer of "undefined"

@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

Ok, thanks a lot for the correction.

The following line was culprit

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