How to get variable value of requested item into client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 01:46 AM
Hi all,
I'm trying to do the following:
I have a catalog item client script where I want to populate a field of this catalog item form with a value of a variable from a requested item.
Hereunder is my snippet code:
//I set 2 variables to find needed requested item
var company = g_form.getValue('my_company');
var req_item_category_sys_id = '7de5ec5d3ee440f1857b576fe4f10096';
//I use gliderecord to call sc_req_item table and filter with company and category
var join_req = new GlideRecord('sc_req_item');
join_req.addQuery('company', company);
join_req.addQuery('cat_item', req_item_category_sys_id );
join_req.orderByDesc('opened_at');
//join_req.setLimit(1);
join_req.query();
if(join_req.next()) {
//if result found, populate my catalog item field with value of "my_request_item_variable_value"
g_form.setValue('my_catalog_item_field', join_req.variables.my_request_item_variable_value);
}
Doing that, I'm getting "Undefined" in my field on the catalog item.
Any suggestions ?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 01:55 AM
is it definitely finding a record? try adding a gs.log statement to print the number it's finding
gs.print('found requested item number: ' + join_req.number);
if it's finding a record, then it's probably not allowing you to see the variables in this way, it would also be better to look up this record via glideAjax in a client script rather than using a gliderecord look up,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 02:01 AM
Hi mguy,
Yes, it is finding the correct requested item.
If I replace in my code with this piece:
g_form.setValue('my_catalog_item_field', join_req.number);
My field in the catalog item form is populated with the right requested item number.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 01:56 AM
- Use a display business rule on the table.
- Add the script to that.
- Compute the value.
- Store the value in scratchpad.
- Access the scratchpad value in client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 02:03 AM
Hi Kalai,
Any example on using this display BR on table in this specific case ?
Thanks in advance