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

Harsh Vardhan
Giga Patron

tried this way ?

$sp.getParameter("sys_id")

Harsh Vardhan
Giga Patron

eg:

 

data.sys_id = (input && input.sys_id) || options.sys_id || $sp.getParameter("sys_id");

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

Thank you for your quick reply. I'd tried your method and I got this error on the portal:

find_real_file.png

When you open the portal approval form, Do you have sys_id on your url ?

May i know the widget name which you actually tried to clone ?

Can you share some screenshot of full widget code.