g_form.setLabelOf() not working on Catalog Item in Helsinki

stephaniet
Kilo Expert

I have the following catalog client script created on a Catalog Item.   It is supposed to change the label of the variable 'network_drives' to what is listed below.   I get the alert, so I know the if statement is correct, but nothing happens to the label.   Does anyone know what is wrong here?

I am currently on Helsinki Patch 11.   I have tried setting the UI Type to be only desktop as well and no change.   I've also changed what it applies on so it will only run on the catalog item, and same thing happens.   I have also confirmed the 'network_drives' variable name is spelled correctly.

Applies to: A Catalog Item

UI Type: Both

Type: onChange

Variable name: mirror;

Applies on Catalog Item, Requested Item and Catalog Tasks views

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

//Type appropriate comment here, and begin script below

if(newValue=='true'){

alert('change label');

g_form.setLabelOf('network_drives','List additional Network Drives or DLs needed');

}

}

5 REPLIES 5

Tony DiRienzo
Giga Guru

I know this post is old, but I could not find an answer to this on Community so I wrote my own solution. I thought I would share it in case anyone else was having the same question.

This solution will work for Service Catalog, Service Portal, and for the variable maps on another record (such as RITM, TASK, or the target record for a record producer).

function onChange(control, oldValue, newValue, isLoading) {
	// The label update should run onLoad and onChange 
	// so it should come before the isLoading check
	var fieldname = "your_field";
	var labelText = "Default label text";

	if (newValue == "your value") {
		labelText = "Modified label text";
	}

	try {
		// This works in Service Catalog, RITM, TASK, and record views
		var field = g_form.resolveNameMap(fieldname);
		var label = g_form.getLabel(field);
		label.textContent = labelText;
	}
	catch (e) {
		// This works in Service Portal and Now Mobile app
		g_form.setLabelOf(fieldname, labelText);
	}
	
	if (isLoading || newValue == "") {
		return;
	}
	
	// Other code that should not run onLoad can go here
}

I hope this helps someone.