get all variables from RITM in flow designer script

BarORen
Tera Contributor

Hi,

im building a script that is making a post request and passing a json, the json needs to be built from all the variables in the RITM,i cant find a way to get all of the variables as object or something like that,i dont want to make a variable for each one because my RITM is built from catalog task that has a lot a variables and also different set of variables (depending on the product chosen),

ive tried using the fd_data but haven't found a way to get all the vars, just a specific one ,

please help,

Thanks!

 

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

You can query the mtom table to get the variable values. You can modify the below script as per your need an build a JSON.

function getVariables()
{
	var vtp='';
	var v = new GlideRecord('sc_item_option_mtom');
	v.addQuery('request_item', current.sys_id);
	v.orderBy('sc_item_option.order');
	v.query();
	while (v.next()) {
		if (vtp.length >= 0) {
			/*****************************
			This code dynamically pulls the questions from the forms in the order they are presented (numerically)
			and then displays them in a consistant readable format.
			Right now nothing links to any records but can with some slight changes to this code.
 			*****************************/
			if (v.sc_item_option.value.getDisplayValue() != '') { /*if the value is blank, don't print*/
				if (v.sc_item_option.item_option_new.type == 1) { //Yes / No
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 2) { //Multi Line Text
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 3) { //Multiple Choice
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 4) { //Numeric Scale
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 5) { //Select Box
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 6) { //Single Line Text
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 7) { //Check Box
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 😎 { //Reference
					var referencegr = new GlideRecord(v.sc_item_option.item_option_new.reference);
					referencegr.addQuery('sys_id', '=', v.sc_item_option.value);
					referencegr.query();
					while (referencegr.next()) {
						vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + referencegr.getDisplayValue() + '\n';
					}
				}
				if (v.sc_item_option.item_option_new.type == 9) { //Date
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				if (v.sc_item_option.item_option_new.type == 10) { //Date/Time
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				/*
				if (v.sc_item_option.item_option_new.type == 11) { //Label
					//Do nothing
				}
				if (v.sc_item_option.item_option_new.type == 12) { //Break
					//Do nothing
				}
				if (v.sc_item_option.item_option_new.type == 13) { //Not Listed
					//Do nothing
				}
				if (v.sc_item_option.item_option_new.type == 14) { //Macro
					//Do nothing
				}
				if (v.sc_item_option.item_option_new.type == 15) { //UI Page
					//Do nothing
				}
 				*/
				if (v.sc_item_option.item_option_new.type == 16) { //Wide Single Line Text
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
				/*
				if (v.sc_item_option.item_option_new.type == 17) { //Macro with Label
					//Do nothing
				}
 				*/
				if (v.sc_item_option.item_option_new.type == 18) { //Lookup Select Box
					var lsbgr = new GlideRecord(v.sc_item_option.item_option_new.lookup_table);
					lsbgr.addQuery('sys_id', '=', v.sc_item_option.value);
					lsbgr.query();
					while (lsbgr.next()) {
						vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + lsbgr.getDisplayValue() + '\n';
					}
				}
				/*
				if (v.sc_item_option.item_option_new.type == 19) { //Container Start
					//Do nothing
				}
				if (v.sc_item_option.item_option_new.type == 20) { //Container End
					//Do nothing
				}
 				*/
				if (v.sc_item_option.item_option_new.type == 21) { //List Collector
					var list = v.sc_item_option.value.getDisplayValue();
					var listarray = list.split(',');
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': \n';
					for (i = 0; i < listarray.length; i = i + 1) {
						var igr = new GlideRecord(v.sc_item_option.item_option_new.list_table);
						igr.addQuery('sys_id', '=', listarray[i]);
						igr.query();
						while (igr.next()) {
							vtp += '- ' + igr.getDisplayValue() + '\n'; //displayvalues
						}
						//vtp +=  'i = ' + i + '- ' + listarray<i> + '\n';//sys_ids
					}
				}
				if (v.sc_item_option.item_option_new.type == 22) { //Lookup Multiple Choice //success
					vtp += '' + v.sc_item_option.item_option_new.getDisplayValue() + ': ' + v.sc_item_option.value.getDisplayValue() + '\n';
				}
			}
		}
	}
	return vtp;
}

 


Please mark this response as correct or helpful if it assisted you with your question.

Hi,

the script is inside flow designers,

do i still need to use Glide record? 

there is no easier way to get all variables thru the fd?

if not , where do i use this snippet in the script part or in the variable script part (input for script)

Thanks

Bar