Based on Assignment group of Catalog Task,How can we hide Catalog Item variables(RITM Variables)?

VIKASM535239375
Kilo Sage

Based on Assignment group of Catalog Task,How can we hide Catalog Item variables(RITM Variables)?

3 REPLIES 3

DrewW
Mega Sage
Mega Sage

You should be able to use a UI policy on the catalog item that runs only on the catalog task.

Please provide the condition based on Assignment group of Catalog Task, How can we hide Catalog Item variables(RITM Variables) to create UI policy

I forgot that you cannot pick a field, only a variable in a cat item UI Policy.  

 

So the easiest option is to use an onLoad script on the cat item to check to see what the group is and then hide vars you do not want them to see.  Downside is that you have to save the record to see the fields change.

 

You could also use a cat item onload script and addEventListener and g_form.getControl() to add an onChange event to the assignment group field that will update things.

 

Here is an example from our client script "Set file name extn" on the sys_export_set table.

function onLoad() {

	var name = g_form.getControl('name');
	name.addEventListener('change', setFileName);
	
	var format = g_form.getControl('format');
	format.addEventListener('change', setFileExtnAndMaxRow);
		
	//On load always set the correct max row for the selected format
	setMaxRowDefaultValue();

	//Don't build the filename unless it is missing
	var fName = g_form.getControl('file_name');
	if (fName.value === ''){
		setFileName();
	}
	
}

function setFileExtnAndMaxRow() {
	setMaxRowDefaultValue();
	setFileExtn();
}

function setFileName() {
	var name = g_form.getControl('name');
	var fName = g_form.getControl('file_name');
	var format = g_form.getControl('format');
	
	if (name.value === "") {
		fName.value = "";
		return;
	}
	
	var fileName = name.value.toLowerCase();
	fileName = getNormalizeFileName(fileName);
	fName.value = fileName;
	
	setFileExtn();
}

function setMaxRowDefaultValue() {
	var max = g_form.getControl('max_rows');
	var format = g_form.getControl('format');
	
	var esajax = new GlideAjax('ExportSetHelper');
	var propertyName = 'glide.' + format.value.toLowerCase() + '.export.limit';
	esajax.addParam('sysparm_name', 'getMaxRowProperty');
	esajax.addParam('sysparm_propertyName', propertyName);
	esajax.getXML(function(resp) {
		var rootNode = resp.responseXML.getElementsByTagName('xml');
		var maxValue = rootNode[0].getAttribute('answer').replace(',', '');
		max.placeholder = maxValue;
		if (max.value == "0") //Allow the placeholder to be visible
			max.value = "";
	});
}

function setFileExtn() {
	var format = g_form.getControl('format');
	var fName = g_form.getControl('file_name');
	var fNameValueNoExtn = getFileNameNoExtn(fName.value);
	
	if (format.value == "XML")
		fNameValueNoExtn += ".xml";
	else if (format.value == "Excel")
		fNameValueNoExtn += ".xls";
	else if (format.value == "XLSX")
		fNameValueNoExtn += ".xlsx";
	else if (format.value == "CSV")
		fNameValueNoExtn += ".csv";
	else if (format.value == "JSON")
		fNameValueNoExtn += ".json";
	fName.value = fNameValueNoExtn;
}

function getNormalizeFileName(name) {
	var fNameNoExtn = getFileNameNoExtn(name);
	
	fNameNoExtn = fNameNoExtn.toLowerCase().replace(/[^a-zA-Z0-9_]/g, '_');
	if (fNameNoExtn.length > 36) {
		fNameNoExtn = fNameNoExtn.substring(0, 36);
	}
	return fNameNoExtn;
}

function getFileNameNoExtn(fName) {
	var fNameNoExtn = fName;
	if (fNameNoExtn.indexOf('.') != -1) {
		fNameNoExtn = fNameNoExtn.substring(0, fNameNoExtn.indexOf('.'));
	}
	return fNameNoExtn;
}