How to get query sys_id of current.sys_id Service Portal

Learning Guy
Tera Contributor

Hi SNOW Community,

I have a question regarding a small issue that I'm having. I've created a widget that will live on the Service Portal to allow an admin to Accept or Reject requests. 

The data for the widget is pulling from the Approvals (approval_approver) table. Under my GlideRecord, I have a query that checks for the state as requested. (Ex. addQuery('state', 'requested'))

To narrow down the search, I tried entering addQuery('sys_id', current.sys_id). When I use this query, my script breaks and I get an error on the Service Portal end. 

Here's a sample of the GlideRecord script I've written to Accept. 

//Accept Request
if(input && input.action=="acceptApproval") {
    var inRec1 = new GlideRecord('sysapproval_approver');
    inRec1.addQuery('state', 'requested');
    //inRec1.get('sys_id', current.sys_id);
    inRec1.query();
    if(inRec1.next()) {
        inRec1.setValue('state', 'Approved');
        inRec1.setValue('approver', gs.getUserID());
        gs.addInfoMessage("Accept Approval Processed");
        inRec1.update();
    }
}

I've research the web, tried using $sp.getParameter() as a work-around and no change.

I would really appreciate any help or insight on what I can do different to get script to work and filter the right records.

find_real_file.png

19 REPLIES 19

find_real_file.png

Just confirming, When you open the portal page where you added this widget, Do you have sys_id on your url ?

try this one in log ,

 

 

eg:

 

var gr = $sp.getRecord();
gs.info('ID is '+ gr.getUniqueValue();

 

I'm not seeing a URL. I'm still novice to a lot of the testing features in ServiceNow. If I'm doing something wrong, just let me know.

find_real_file.png

Hard to say, i would suggest please check ootb widget and check if any method you are missing. 

 

https://<YourInstanceID>.service-now.com/sp_widget.do?sys_id=33442352cb30020000f8d856634c9c3f&sysparm_record_target=sp_widget&sysparm_record_row=10&sysparm_record_rows=20&sysparm_record_list=nameCONTAINSapproval%5EORDERBYDESCsys_updated_on