Service Catalog: Showing Variable Set Options under Auto-Populate's Dependent Question

Tristan Elmore
Tera Expert

Trying to figure out how to show the variables within a variable set under the auto-populate tab for a catalog item variable.

TristanElmore_0-1696530037433.png

I checked the definitions on the dictionary entry for the dependent question field, which led me to the SNCCatalogUtil script include.

TristanElmore_1-1696530738280.png

 

TristanElmore_2-1696530785749.png

 


It makes sense why I can't see any of the variable set reference fields because a variable can only belong to either a catalog item or a variable set, but not both. The script include checks whether the variable record is on a catalog item or not (i.e., on a variable set) and then filters the variable list down.

Ideally, at least from my perspective, that dynamic reference qualifier would look at the variables specific to the catalog item—as well as include variables on any variable sets on the catalog item as options for the dependent question. Though the latter doesn't seem to be the case on our instance. We're currently on Utah patch 4 hotfix 2b.

I cannot think of a way to readily implement that as of right now, nor do I know if the auto-populate functionality would actually work if I could get that dependent question to show the variable set variables there.


Does anyone have any insight here?

1 ACCEPTED SOLUTION

Looking at your SI function more closely, and the updated one.  I can see they fully intended for this to work, but a simple logic error is preventing it.  You should be able to fix this (until you can upgrade) by copying the SI and updating the function (then calling your new SI from the reference qualifier).  My reference qualifier is exactly the same as yours.

 

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';
	},

I can also confirm that this is not fixed as of Utah patch 7.

 

 

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Hi Tristan,

I've been looking forward to this feature more than any other in the past few years, so I was disheartened to see a break in the feature that didn't seem to have a reason/limitation behind it.  I assume when you are referring to 'variable set' here you mean single row as opposed to multi-row.  Everything else about single row variable sets - client scripts, server scripts,... don't seem to differentiate between a variable belonging to a Catalog Item or within a single row variable set, so I was really hoping for this not to be true.  The good news is, that at least as of Vancouver patch 2, if not before, variables contained within a single row variable set that is associated with the Catalog Item ARE included in the Dependent question reference qualifier.  If the variable I'm trying to auto populate is also in the variable set I will see variables only in the same variable set in this list, and if the variable I want to auto populate is not in a variable set I can see variables that are in single row variable sets attached to the Catalog Item and variables that are not in a variable set in this list!  

Thanks Brad—I appreciate the information and quick reply!

Yes, that's exactly what I was referring to: being able to utilize variables from the variable set or the variables specific to that catalog item interchangeably within the dependent question field.

Probably should've been specific, but you are correct; I am referring to single row variable sets. Also, our instance is on Utah patch 4, hotfix 2b.

Looking at your SI function more closely, and the updated one.  I can see they fully intended for this to work, but a simple logic error is preventing it.  You should be able to fix this (until you can upgrade) by copying the SI and updating the function (then calling your new SI from the reference qualifier).  My reference qualifier is exactly the same as yours.

 

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';
	},

I can also confirm that this is not fixed as of Utah patch 7.

 

 

Using the updated version for the getDynamicValueFieldRefQual function worked like a charm. It wasn't working at first, but after verifying that it was working on my PDI that's on Vancouver; I found that it was a matter of needing to include _getSingleRowVariableSetIdList as well.

I've included the snippet below for anyone else that might come across this. Basically, I created another script include called SNCCatalogUtilCopy and then changed the Reference qual on the Dependent question Dictionary entry as shown below (updating the name of the script include).

TristanElmore_0-1697564384683.png

 

 

 

 

 

	_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';
	},