Catalog Item Auto-populate

anthony_dtf
Tera Contributor

I have a variable called requested_for_email that I'm trying to auto populate depending on a variable called requested_for which references sys_user. I understand that I can simply use the Auto-populate tab but since requested_for is part of a variable set it is not letting me select it. Is there a way around this?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Variables in a single row variable set are available in the Dependent question field as of Vancouver (patch 2 or maybe earlier).  To get this 'fixed' functionality before upgrading, make a copy of the Script Include named SNCCatalogUtil and then change the Reference qual on the Dependent question Dictionary Entry with the updated name.

 

Inside the new version of the SI you need to add the _getSingleRowVariableSetIdList function, and modify the getDynamicValueFieldRefQual function.  Here are those sections from my Vancouver PDI:

_getSingleRowVariableSetIdList: function(catItemId) {
	    var srvsIdList = [];
	    var gr = new GlideRecord('io_set_item');
	    gr.addQuery('sc_cat_item', catItemId);
	    gr.addQuery('variable_set.type', 'one_to_one');
	    gr.query();
	    while (gr.next())
	        srvsIdList.push(gr.getValue('variable_set'));
	    return srvsIdList;
	},

	getDynamicValueFieldRefQual: function(catItemId, variableSetId, variableId) {
	    if (catItemId) {
	        var srvsIdList = this._getSingleRowVariableSetIdList(catItemId);
	        if (srvsIdList.length != 0)
	            return 'cat_item='+catItemId+'^ORvariable_setIN'+(srvsIdList)+'^sys_id!='+variableId+'^typeIN8,31';
	        else
	            return 'cat_item='+catItemId+'^sys_id!='+variableId+'^typeIN8,31';
	    }
	    else if (variableSetId)
	        return 'typeIN8,31^variable_set='+variableSetId+'^sys_id!='+variableId;
	    return 'cat_item=-1';
	},

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Variables in a single row variable set are available in the Dependent question field as of Vancouver (patch 2 or maybe earlier).  To get this 'fixed' functionality before upgrading, make a copy of the Script Include named SNCCatalogUtil and then change the Reference qual on the Dependent question Dictionary Entry with the updated name.

 

Inside the new version of the SI you need to add the _getSingleRowVariableSetIdList function, and modify the getDynamicValueFieldRefQual function.  Here are those sections from my Vancouver PDI:

_getSingleRowVariableSetIdList: function(catItemId) {
	    var srvsIdList = [];
	    var gr = new GlideRecord('io_set_item');
	    gr.addQuery('sc_cat_item', catItemId);
	    gr.addQuery('variable_set.type', 'one_to_one');
	    gr.query();
	    while (gr.next())
	        srvsIdList.push(gr.getValue('variable_set'));
	    return srvsIdList;
	},

	getDynamicValueFieldRefQual: function(catItemId, variableSetId, variableId) {
	    if (catItemId) {
	        var srvsIdList = this._getSingleRowVariableSetIdList(catItemId);
	        if (srvsIdList.length != 0)
	            return 'cat_item='+catItemId+'^ORvariable_setIN'+(srvsIdList)+'^sys_id!='+variableId+'^typeIN8,31';
	        else
	            return 'cat_item='+catItemId+'^sys_id!='+variableId+'^typeIN8,31';
	    }
	    else if (variableSetId)
	        return 'typeIN8,31^variable_set='+variableSetId+'^sys_id!='+variableId;
	    return 'cat_item=-1';
	},

 

Ankur Bawiskar
Tera Patron
Tera Patron

@anthony_dtf 

try to use onChange client script + GlideAjax then

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader