- 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 10:39 AM
It seems to me that the script should work as long as you are naming the fields correctly. In this line
var subcat = g_form.getValue('subcategory');
you are getting the value of a field named 'subcategory' and in this line
gr.addQuery('u_subcategory', subcat);
you are querying for a field named 'u_subcategory'.
I am not sure if these fields are on the same table. If everything you are doing with this code is on the same table, then one of those fields is named incorrectly and I assume that the field should be named 'u_subcategory'. You did mention that changing the subcategory doesn't change the value from undefined and I assume this is why.
Below is the fixed code assuming it all is on the same table:
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (g_form.getValue('caller_id') != ""){
var subcat = g_form.getValue('u_subcategory');//Notice I changed the name of the field to u_subcategory
var prod = g_form.getValue('u_product');
g_form.setValue('u_assignment_assistance', getAssignment(subcat, prod));//Notice I passed in prod like Solutioning Now did
}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;
}//end if
}//end function
}//end onChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 11:07 AM
No they are on separate tables and and the fields are typed correctly. Hmmm... everything looks right though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 11:37 AM
Hi Jared,
Try modifying the getAssignment function as follows and see if that helps:
function getAssignment(subcat, prod) {
var result = '';
var gr = new GlideRecord('u_assignment_assistance');
gr.addQuery('u_product', prod);
gr.addQuery('u_subcategory', subcat);
gr.query();
if (gr.next()) {
result = gr.u_assignment_group.sys_id.toString();
}//end if
return result;
}//end function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:11 PM
I tried, but no dice... I even modified the IF statement to look at the subcategory field rather than the caller_id and the change still does not trigger the value. It's just stuck on 'undefined'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 12:13 PM
Sprinkle console.log() statements on every line. See if the code stops somewhere, see what the variable values are in the if statement and in the getAssignment function. Let us know what you find.