How to run "Populate primary resource attributes" from background script

DhathriC
Giga Contributor

I have to create a Action in flow designer, where I will be passing user sys_id. I want to trigger "Populate primary resource attributes".

12 REPLIES 12

DhathriC
Giga Contributor

I'm trying below script:

 

// If you only have sys_user.sys_id, resolve the profile first:
var userSysId = '001701001b881d94f7590f6cdc4bcb5a';
var prof = new GlideRecord('sn_employee_profile');
prof.addQuery('user', userSysId);
prof.setLimit(1);
prof.query();
if (prof.next()) {
  gs.info('Done for profile ' + prof.getUniqueValue());
  svc.populatePrimaryAttrsForResource(prof.getUniqueValue());
  gs.info('Done for profile ' + prof.getUniqueValue());
 
var cfg = {
  "primary_resource_group": {"userRefField":"user"},
  "primary_resource_skill": {"userRefField":"user"},
  "primary_resource_role":  {"userRefField":"user"}
};
var svc = new global.ResourceProfileSyncServiceSNC(cfg);
} else {
  gs.warn('No employee profile found for user ' + userSysId);
}
 
I'm getting below error:
I added Restricted caller access, Ran the script in Employee profile scope. Still getting error like below.
Source descriptor is empty while recording access for table sn_employee_profile: no thrown error
Security restricted: Read operation on table 'sn_employee_profile' from scope 'Global' was denied because the source could not be found. Please contact the application admin.
Security restricted: Read operation on table 'sn_employee_profile' from scope 'Global' was denied. The application 'Employee Profile' must declare a Restricted Caller Access privilege. Please contact the application admin to update their access requests.
*** Script: No employee profile found for user 001701001b881d94f7590f6cdc4bcb5a

@DhathriC 

check if any Restricted caller access is blocking

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

I have given access in "Restricted caller access priveliges"