- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 09:40 AM
Hi all!
I am having trouble with the following code. I have a table with 3 columns (product, subcategory, assignment group) and I am trying to build a client script to query that table when there is a change to the incident subcategory field where the product and subcategory fields match that of the current record then return the assignment group information. Basically it will serve as a assignment group help for the helpdesk. But it is not working. I have never had to use two conditions for a glide record query before so I think that's where I'm goofing it up.
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (g_form.getValue('caller_id') != "")
{
var subcat = g_form.getValue('subcategory');
var prod = g_form.getValue('u_product');
g_form.setValue('u_assignment_assistance', getAssignment(subcat));
}
else
{
g_form.setValue('u_assignment_assistance', "");
}
function getAssignment(subcat)
{
var gr = new GlideRecord('u_assignment_assistance');
gr.addQuery('u_product', prod);
gr.addQuery('u_subcategory', subcat);
gr.query();
if(gr.next())
{
return gr.u_assignment_group;
}
}
}
Solved! Go to Solution.
- Labels:
-
Integrations
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 09:46 AM
Hello,
Try below script:
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (g_form.getValue('caller_id') != "")
{
var subcat = g_form.getValue('subcategory');
var prod = g_form.getValue('u_product');
g_form.setValue('u_assignment_assistance', getAssignment(subcat,prod));
}
else
{
g_form.setValue('u_assignment_assistance', "");
}
}
function getAssignment(subcat,prod)
{
var gr = new GlideRecord('u_assignment_assistance');
gr.addQuery('u_product', prod);
gr.addQuery('u_subcategory', subcat);
gr.query();
if(gr.next())
return gr.u_assignment_group;
}
Please mark answer as correct/helpful, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:15 PM
You might want to make that alert(); statements since you're inside of a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:16 PM
Whoops, good catch. I changed my comment to console.log().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:28 PM
Jared,
One other thing you might want to try is to execute the getAssignment function prior to using the result in a g_form.setValue function.
I.E.
var assignmentValue = ''; // Added this
assignmentValue = getAssignment(subcat, prod); // Added this
g_form.setValue('u_assignment_assistance', assignmentValue); // Used new variable here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:40 PM
So I added some alerts in there and to my surprise is it actually alerting the correct value! But it still will not populate that value into the field.
if (g_form.getValue('subcategory') != "")
{
var subcat = g_form.getValue('subcategory');
var prod = g_form.getValue('u_product');
alert(subcat);
alert(prod);
//g_form.setValue('u_assignment_assistance', getAssignment(subcat,prod));
alert(getAssignment(subcat,prod));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:43 PM
If it's a reference field then make sure the value that is alerting is the sys_id of the target reference record. That is what would need to be set via the setValue function.