How to get values from a watchlist and print maximum value in a field ?

Khushboo8
Tera Contributor

My requirement is that suppose there is watchlist named 'services' on a form in which multiple services from 'services' custom table can be added. Now the 'services' custom table has 'tier' field. So, whichever service in the watchlist has lowest tier that service's tier should display in 'Tier' field on the form ?

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think I would use on onchange client script on the services watch list field that does GlideAjax to push the value of the watch list to a script include. The script include would then push that value to an array, loop through each element and do a GlideRecord.get() to look at the record and find the one with the lowest tier. You would then return that tier back to the client script and set the value of the field.



GlideAjax


Khushboo8
Tera Contributor

Thanks Brad,



I used the below script include-


var SettingTier = Class.create();


SettingTier.prototype = Object.extendsObject(AbstractAjaxProcessor, {


    settingapptier : function(){


  var b;


var serv=current.u_services_affected.toString('u_services_affected');


  var servList=serv.split(',');


  var tier=current.u_tier___application;


for (var i=0; i < servList.length; i++)



  {



  if(serv!= '' && servList.length > 0)


  //alert("Reference value is: " + servList[i]);


  {


  var a = new GlideRecord('cmdb_ci_service');


a.addQuery('sys_id', servList[i]);


a.orderByDesc('u_tier_rating');  


a.chooseWindow(0, 1);


a.query();  


  if (a.next()) {


    b= a.u_tier_rating;


  }


  return b;


  }


}


  } ,


type:' SettingTier'


});



Client Script:


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }




var ga = new GlideAjax('SettingTier');


ga.addParam('sysparm_name','settingapptier');


  ga.getXMLWait();


alert("hello"+ga.getAnswer());




}



Above client script is returning null,please help me with it



Regards,Khushboo


You can't reference current in your script include. You'll have to pass the values from the client side to the script include using g_form.getValue() to grab the value and passing it as a parameter.


Hi Brad,



Can you help me with how can i pass parameters in above script?