Getting value of the field instead of sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2013 08:21 AM
I have a script where I do a GlideRecord query to the request table. Once I get the records, I am getting to the value of the opned by field. But since opened by is a reference field, it is returning sys_id. How can I get the displayed value ?
Below is the script :
var gr = new GlideRecord("sc_req_item");
gr.addQuery("u_requested_for", g_form.getValue("emp_name"));
gr.addQuery("stage",'!', "waiting_for_approval");
gr.query();
if(gr.next())
{
alert("A request has already been submitted by " + gr.opened_by); // this is returming sys_id, I need the value
}
Please let me know if anyone has any suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2018 01:45 PM
Deepak,
Your suggestion makes sense, but what can you do if you have multiple reference fields? Do I have to use some if statements for each reference field?
Here's my current code, it works great except I get the sys_id anytime we use a reference variable.
var item = GlideRecord("sc_req_item");
item.addQuery('sys_id','71bb57fb0f93030059daba8ce1050e11');
item.query();
while(item.next()){
var c_item = GlideRecord("sc_cat_item");
c_item.addQuery('sys_id',item.cat_item);
c_item.query();
while(c_item.next()){
gs.info("<a href='" + "sp?id=ticket&table=sc_req_item&sys_id=" + item.sys_id + "'>" + item.number + "</a>: " + c_item.name + " <br />");
var item_vbls = new GlideRecord("sc_item_option_mtom");
item_vbls.addQuery('request_item', item.sys_id);
item_vbls.orderBy('sc_item_option.order');
item_vbls.query();
while(item_vbls.next()) {
gs.info("<b>" + item_vbls.sc_item_option.item_option_new.question_text + ": </b>" + item_vbls.sc_item_option.value + "<br />");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 02:51 AM
To get the display value at server side... user gr.getDisplayValue('field_name')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 08:28 AM
I actually got it work using functions GlideappVariablePoolQuestionSet() and getFlatQuestions(). Here's the snip it of code that I used:
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(req.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
gs.info("<b>" + vs.get(i).getLabel() + ":</b> " + vs.get(i).getDisplayValue() + "<br />");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 09:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2017 03:55 AM
if you are hitting a refrence field by GlideRecord API and to getDisplayValue not sys_id you must do following:
1. gr.getDisplayValue('field_name')
2. Ensure that the particular field also has a display value true in table on which you are hitting glide record else it will show sys_id.