How to retrieve value of Request State of a Requested Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:50 AM
Hi guys,
I need to display the request state of a requested catalog item in my Service Portal landing page. For some reason I am unable to get the value of the field.
I am also confused on its supposed value..
In the list view and on the Form, the value is "Approved"
however when I checked the XML, the value of the request_state field is "in_process"
Anyway, I was hoping to get the value "Approved"..Here's my code:
(function() {
// populate the 'data' object
//e.g., data.table = $sp.getValue('table');
data.pirs = [];
var gr1 = new GlideRecord('task');
var qc1 = gr1.addQuery('sys_class_name', 'u_pir');
qc1.addOrCondition('sys_class_name', 'sc_request');
qc1.addOrCondition('sys_class_name', 'u_pir_task');
gr1.addActiveQuery();
gr1.addQuery('opened_by', gs.getUserID());
gr1.query();
data.count = gr1.getRowCount();
var gr = new GlideRecord('task');
var qc2 = gr.addQuery('sys_class_name', 'u_pir');
qc2.addOrCondition('sys_class_name', 'sc_request');
qc2.addOrCondition('sys_class_name', 'u_pir_task');
gr.addActiveQuery();
gr.addQuery('opened_by', gs.getUserID());
gr.orderByDesc('sys_updated_on');
gr.setLimit(5);
gr.query();
data.count2 = gr.getRowCount();
while(gr.next()) {
var pir = {};
var dtReq = gr.getDisplayValue('opened_at');
var dtOnly = dtReq.substr(0,10)
var formType = gr.sys_class_name;
if(formType=='sc_request'){
pir.stage = gr.getDisplayValue('request_state');
}else if((formType=='u_pir')) {
pir.stage = gr.getDisplayValue('state');
}
console.log('stage=' + gr.request_state);
console.log('formType' + formType);
pir.number = gr.getDisplayValue('number');
pir.daterequest = dtOnly;
pir.sys_id = gr.getUniqueValue();
pir.sys_updated_on = gr.getValue('sys_updated_on');
data.pirs.push(pir);
}
})();
Greatly appreciate any help. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:25 AM
No worries, thanks Chuck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:06 AM
I noticed gr is a task object and request_state only exists on the sc_request table. That may be causing your issue. You may need to initiate a new GlideRecord of type sc_request to get the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:25 AM
Actually after doing a little digging, there is a business rule called "Set Request State" running on the sc_request table that is setting it to in_process:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:37 AM
Thanks Michael for the reply.
I gave it a try and got same result
if(formType=='sc_request'){
//get state of sec_item
var scgr = new GlideRecord('sc_request');
console.log('sys_id='+ gr.getUniqueValue());
scgr.addQuery('sys_id', gr.getUniqueValue());
scgr.query();
console.log('here 2');
// if(scgr.hasNext()){
pir.stage = scgr.getDisplayValue('request_state');
console.log('val=' + scgr.getDisplayValue('request_state'))
// }
}else if((formType=='u_pir')) {
pir.stage = gr.getDisplayValue('state');
}
I also realized that sc_request table is extended from the Task table that's probably why i'm getting the same behaviour..
Regina