How to get values from a watchlist and print maximum value in a field ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2017 10:20 AM
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 ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2017 01:07 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2017 09:47 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2017 09:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2017 04:36 AM
Hi Brad,
Can you help me with how can i pass parameters in above script?