Unable to query the HR profile data using scripted rest API on sn_hr_core_profile table? I am always getting response as record not found.

Shailesh Kodgir
Tera Contributor

Hi All,

I am trying to update the sn_hr_core_profile table with additional fields for each record using a scripted rest API.

This API will have the logic to get the sys_id of the employee record using the Employee number and then use that sys_id to populate additional fields for each record received from the input JSON(this can have multiple nodes).

I am always stuck at the first point itself where the GlideRecord for sn_hr_core_profile table is not giving me any output for the gr.query().

I am sure this has something to do with the ACL's but I am not able to identify the real cause. Any pointers here are much appreciated.

7 REPLIES 7

Arav
Tera Guru
Tera Guru

Hi,

Please add a screenshot of your script so we could help.

Thanks,

Arav

Hi Arav, Thanks for your time. Please find the script below. I just trying to do a GET operation but seems like it says record doesn't exist. Looks like an ACL issue but not sure why?

 

 var emplid = request.pathParams.emplid;
    gs.info("emplid is : "+emplid);
    var gr = new GlideRecordSecure('sn_hr_core_profile');
    //var gr = new GlideRecordSecure('incident');
    gr.addQuery('employee_number',emplid );
    //gr.addQuery('sys_id',emplid );
    gr.query();
    gs.info("outside loop : "+gr.employee_number);
    if(gr.next()){
        gs.info("inside loop : "+gr.employee_number);
        var respBody = {};
        respBody.emp_number = gr.employee_number;
        response.setBody(respBody);
        response.setStatus(201);
    }
    //response.setStatus(200);
    //response.setBody({'message': 'success' });
    return;

Hi Shailesh, 

The script is working for me and so I have a few additional questions.

a. Is the REST API written in Human Resources Core scope ?

b. Why is there a need to use "GlideRecordSecure" vs "GlideRecord" ? Are you trying to hide a few profile records ? Please check the "read" ACL on "sn_hr_core_profile" to see if it has been customized

c. As you are using pathParams, is the relative path properly configured in REST message ? Before I ask more on this, is the snippet below printing the employee id being passed ?

    gs.info("emplid is : "+emplid);

Thanks,

Arav

Shailesh Kodgir
Tera Contributor

Hi Arav, Thanks for your time on this.

Please find below my answers here.

a)  Is the REST API written in Human Resources Core scope ?

Ans) Yes its in Human resources Core scope.

 b. Why is there a need to use "GlideRecordSecure" vs "GlideRecord" ? Are you trying to hide a few profile records ? Please check the "read" ACL on "sn_hr_core_profile" to see if it has been customized

Ans) Since this data is sensitive I saw in service now Documentation to use GlideRecordSecure instead of GlideRecord. Not trying to hide any profile records.  I don't see any customizations on this.

c. As you are using pathParams, is the relative path properly configured in REST message ? Before I ask more on this, is the snippet below printing the employee id being passed ?

    gs.info("emplid is : "+emplid);

Ans) Yes its printing the correct empl id.

 

Just FYI, In fact I tried the same code for incident table and things works well here.

 

Regards,

Shailesh