The CreatorCon Call for Content is officially open! Get started here.

Glide record query with and operator

jared_wentzel
Kilo Contributor

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;

              }

      }

}

1 ACCEPTED SOLUTION

solutioningnow
Giga Guru

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


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


View solution in original post

15 REPLIES 15

solutioningnow
Giga Guru

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


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Jared,



The best way is to use "Assignment rules"


Please check the below wiki link for further info


Defining Assignment Rules - ServiceNow Wiki


Kindly let me know if you have any questions.

Mark this thread as answered if it solves your problem



Thanks,


Pradeep Sharma


solutioningnow
Giga Guru

Hello Jared,



You can go for Data Lookup Rules as Assignment Rules runs only on creation of ticket.


While defining Data Lookup Rules you can define When to run like Insert/Update.



Please mark answer as correct/helpful, if it was really helpful 🙂



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


I'll look into those other options, thank you! Also, I tried the script you suggested and it does make sense but I am still getting the same results. It says 'undefined' in the field I'm pointing at and changing the subcategory value is not changing the value