- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 07:44 AM
I’m trying to query all approval records which were opened for records on the sc_req_item table.
If they aren’t processed, they should be closed after 3 weeks of inactivity.
I have issues with getting only records with sc_req_item as a parent to show up.
I thought you could perhaps verify what I’m doing here, because I’ve tried the below in other ways, but I’m missing something: I tried to use the sysapproval field before, and didn’t use the ‘=’ operator before.
var dbgSrc = "JP"; //for gs.log statements’ source
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('document_id.sys_class_name', '=', 'sc_req_item'); //the record that the approval is for must be under provided table name
gr.addNotNullQuery('sysapproval.number');
gr.addActiveQuery();
gr.setLimit(100);
gr.query();
If I then query for the results this way:
var dbgTempArr = [];
while(gr.next()) {
var sid = gr.getUniqueValue();
if (gr.document_id.sys_class_name != "sc_req_item")
dbgTempArr.push("gr.next() SID: "+sid+
" for: "+gr.document_id.number + " @ " + gr.document_id.sys_id +
" table: " + gr.document_id.sys_class_name);
}
gs.log(dbgTempArr, dbgSrc);
I get not precisely what I’ve been asking for:
Sometimes it even queries results which shouldn’t be there – a record for example doesn’t have the document_id filled out – instead it only had sysapproval (must’ve been a bug that they already fixed).
I think it shouldn’t be there since I’m using .addNotNullQuery for sysapproval’s number field one line below sys_class_name – if sysapproval is null, surely its fields should also be null?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 08:02 AM
You could just query on the "source_table" field instead:
gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('source_table', 'sc_req_item'); //document_id depends on source_table
gr.addNotNullQuery('sysapproval.number');
gr.addActiveQuery();
gr.setLimit(100);
gr.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 07:57 AM
Hello,
Try
gr.addEncodedQuery('sysapproval.sys_class_name=sc_req_item');
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 08:02 AM
You could just query on the "source_table" field instead:
gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('source_table', 'sc_req_item'); //document_id depends on source_table
gr.addNotNullQuery('sysapproval.number');
gr.addActiveQuery();
gr.setLimit(100);
gr.query();