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 09:52 AM
Hi Regina,
Try replacing the highlighted line with
pir.stage = gr.request_state.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:57 AM
Thanks for the reply Anurag.
When I replaced the code with yours, I'm getting "undefined"..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:57 AM
any ideas ctomasi?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:02 AM
That's bizarre. I have not seen getDisplayValue() behave that way. No ideas at the moment, but I'll let you know if I come up with anything.