Passing the value of a field in a Table to Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 09:50 AM
Hi guys,
I need a simple thing (it´s seems i guess) but right now is not working.
Basically i have a form that is part of a catalog item that contains different variables (see the image below).
In this form we have Agreed rate and i just want that this field to be fulfill like i have in the workspace (see the image below)
The client script that i did is like this: (the table that cointains the information is x_cioa2_hcx_t_engagement_hcx)
----------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 11:33 AM
Hi Diego,
Your immediate problem is that hcxTable.query(); doesn't position you on a record, it just gathers the data. You need to use hcxTable.next() to move through the record(s). Even more basic, unless you are passing a sys_id to a table, the query should have two parameters, field and value. If you know that there can only be one value returned, you can also use hcxTable.get() which will return one record positioned.
Best practice is to do back end processing (which includes searching a table) in the back end via AJAX and then getting the relevant values from there. The documentation for AJAX is pretty good and can be found here.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 04:01 AM
Hi johnfeist,
I already change the code like you indicated
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var hcxTable = new GlideRecord('x_cioa2_hcx_t_engagement_hcx');
hcxTable.addQuery('suggested_rate', '10');//add rate here
hcxTable.query();
if(hcxTable.next()){
var agreedRate = hcxTable.getValue('suggested_rate');//Check if you have agreed rate field
g_form.setValue('suggested_rate', agreedRate);
g_form.addInfoMessage(agreedRate);
}
else{
g_form.addInfoMessage('test');
}
}
Can you help me?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:06 PM - edited 09-29-2023 12:09 PM
@Diogo Lemos Try updating your code as follows.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var hcxTable = new GlideRecord('x_cioa2_hcx_t_engagement_hcx');
hcxTable.addQuery('suggested_rate','<provide rate here>');//add rate here
hcxTable.query();
if(hcxTable.next()){
var agreedRate = hcxTable.getValue('agreed_rate');//Check if you have agreed rate field
var teste = g_form.getValue('final_travel_expenses');
var currency_code = 'USD';
g_form.setValue('suggested_rate', currency_code + ';' + agreedRate);
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 03:59 AM
Hi Sandeep Rajput,
I already change the code like you indicated
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var hcxTable = new GlideRecord('x_cioa2_hcx_t_engagement_hcx');
hcxTable.addQuery('suggested_rate', '10');//add rate here
hcxTable.query();
if(hcxTable.next()){
var agreedRate = hcxTable.getValue('suggested_rate');//Check if you have agreed rate field
g_form.setValue('suggested_rate', agreedRate);
g_form.addInfoMessage(agreedRate);
}
else{
g_form.addInfoMessage('test');
}
}
Can you help me?