current.variables contains variable set objects

dan_ke
Giga Contributor

Hi, 

We have a business rule that stores the catalog item variables in the description field in sc_req_item (current.variables). After we upgraded from Kingston to Madrid we got an issue I want to fix without adding container start/end to all our variable sets.

The screenshot below is current.variables (gs.log from Xplore). This example is from a catalog item with four variable sets. The variable sets without container start/end is included as its own object with all its variables inside. You can see that the variables also is present outside of the variable set object as a variable and that's the variable I want in the description field, not the content of the variable set object. The variable set object is stored as 'undefined:<variable name>:<sys:id>' in Description. 

The variable set object is excluded from current.variables if I add a container start/end to the variable sets. But I do not want to create containers in all our variable sets. How do I exclude the variable set object from current.variables or current.variable_pool when I add them to Description? I just need the variables and their value 🙂

 

 

find_real_file.png

 

The variable set property is coming up as undefined:<variable name>:<sys:id> (marked in yellow below) in the Description field.

find_real_file.png

 

Thanks in advance! 🙂

1 ACCEPTED SOLUTION

dan_ke
Giga Contributor

Appearantly the variable set behavior has changed: 
https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/conce...

 

Managed to solve this by modify the script:

var variables = current.variables.getElements(); 

for(var i = 0; i<variables.length;i++){
	
	var v = variables[i].getQuestion();

	if (JSUtil.notNil(v) 
		&& v.getName() != 'requested_for_title' 
		&& v.getName() != 'requested_for_manager' 
		&& v.getName() != 'requested_for_location' 
		&& v.getName() != 'requested_for_department' 
		&& v.getName() != 'requested_for_company' 
		&& v.getName() != 'requested_for'
		&& v.getName() != 'due_date'
		&& variables[i] != ''
		&& variables[i] != 'false'
		&& v.type != 11
		&& v.type != 19
		&& v.type != 20){
		
		notes += v.getLabel() +': ' + v.getDisplayValue() + '\n';
	}
}

 

View solution in original post

2 REPLIES 2

dan_ke
Giga Contributor

Appearantly the variable set behavior has changed: 
https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/conce...

 

Managed to solve this by modify the script:

var variables = current.variables.getElements(); 

for(var i = 0; i<variables.length;i++){
	
	var v = variables[i].getQuestion();

	if (JSUtil.notNil(v) 
		&& v.getName() != 'requested_for_title' 
		&& v.getName() != 'requested_for_manager' 
		&& v.getName() != 'requested_for_location' 
		&& v.getName() != 'requested_for_department' 
		&& v.getName() != 'requested_for_company' 
		&& v.getName() != 'requested_for'
		&& v.getName() != 'due_date'
		&& variables[i] != ''
		&& variables[i] != 'false'
		&& v.type != 11
		&& v.type != 19
		&& v.type != 20){
		
		notes += v.getLabel() +': ' + v.getDisplayValue() + '\n';
	}
}

 

demet1
Giga Contributor

Hi,

could you please tell how can I get the value from the variable[i] value?

Thanks.