How to : Based on Each values Selected in the List Collector, Manipulate other Variables
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:24 AM
Lets say you have a List Collector Variable in Catalog item, referencing sys_user table.
User table also contains Departments, on the Users Selected in the List Collector, based on the departments, we can manipulate other variables of a Catalog Item.
Step 1:
Create a Client Callable Script include
var devDepartment = Class.create();
devDepartment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getDept: function() {
//passing the Schema Parameter(from the List Collector User table) and validating it
var dept = this.getParameter('sysparm_dept');
var mgr = new GlideRecord("sys_user");
mgr.addQuery("department", "IT");
mgr.addQuery("sys_id", "IN", dept);
//Query initiation and Return value if True or False
mgr.query();
return mgr.hasNext();
},
type: 'devDepartment'
});
Step 2:
create an OnChange catalog client script calling the above the script include
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
// onloading the below variable will be set to Visible False
g_form.setVisible('field name', false);
return;
}
var ga = new GlideAjax('devDepartment');
ga.addParam('sysparm_name', "getDept");
ga.addParam('sysparm_dept', g_form.getValue('list collector field name'));
ga.getXMLAnswer(function(answer) {
g_form.setVisible('field_name', answer);
});
}
If you want to use multiple departments then minor modification will be made in the script include addQuery ( to allow multiple deparments )
or on better note, create another similar function in the same script include and call it using a catalog client script.
0 REPLIES 0