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

Hi Shailesh,

Can you please do the following ?

a. Change "GlideRecordSecure" to "GlideRecord" and try as the intention is to query any HR profile.

b. Enclose the entire code in try - catch block and share if there is any error

c. Add "ELSE" for the "IF" and check if it is entering that block

d. Please also share the output of all log statements

Thanks,

Arav

Hi Arav,PFB the updated script.

var emplid = request.pathParams.emplid;
    gs.info("emplid is : " + emplid);
    var gr = new GlideRecord('sn_hr_core_profile');
    //var gr = new GlideRecordSecure('incident');
    try {
        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);
        }
        else{
             response.setStatus(200);
            response.setBody({
            'message': 'No record found with the matching ID'
        });
        }
    } catch (e) {
        gs.info("exception is " + e);
        response.setStatus(200);
        response.setBody({
            'message': 'failure'
        });
    } //response.setStatus(200);
    //response.setBody({'message': 'success' });
    return;

}

 

I am still not seeing any difference and also I used the ACL debugger to see if any ACL's are creating an issue but couldn't find anything as such.

So is it getting into the ELSE block or into CATCH ? What is the output you are seeing ?

Also, how are you executing this ? From SN REST API explorer or an external tool ?