Change label for catalog variable

sanvi
Tera Expert

Hi All,

I have a requirement to change the label of a variable in a catalog item, tried using 'setLabelOf' but its not working as its not supported for catalog forms and i cannot change the label directly because this variable is part of variable set which is being used by multiple other forms.

Can anyone suggest for any alternative. below are the requirement.

Existing label - Do you need a official service along with request.

New label - Do you need data service along with the request

1 ACCEPTED SOLUTION

@sanvi 

Here you go to make it work for both native + portal

onLoad Catalog Client Script on Your Catalog Item

UI Type - ALL

Isolate Script - False

a) This field is not on form but from list you can make it false

Script:

function onLoad(){

	setTimeout(function(){

		var newLabel = 'My Label';
		var oldLabel = 'My New Label';

		if(window != null){
			$j("span").filter(function() {
				return ($j(this).text() === oldLabel);
			}).html(newLabel);
		}
		else{
			var aTags = this.document.getElementsByClassName("ng-binding");
			var found;
			for (var i = 0; i < aTags.length; i++) {
				if (aTags[i].textContent.toString() == oldLabel) {					
					aTags[i].innerHTML = newLabel;
					break;
				}
			}
		}
	}, 3000);
}

find_real_file.png

Output:

Portal:

find_real_file.png

Native:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Alp Utku
Mega Sage

I would suggest you to create new variable with new label and write catalog client script to hide the old variable from the variable set. 

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

You can refer this link where I have shared solution on how make label as bold

enhance as per your need to change the inner html value

How to make text of Label type in Bold

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@sanvi 

I was able to add the new label for Portal

For native you need to use DOM manipulation somehow

Old - My Label

New - My New Label

Create onLoad Catalog Client Script

function onLoad(){

	setTimeout(function(){ 
		var newLabel = 'Do you need data service along with the request';
		var olLabel = 'Do you need a official service along with request.';

		var aTags = this.document.getElementsByClassName("ng-binding");
		var found;

		for (var i = 0; i < aTags.length; i++) {
			//alert(aTags[i].textContent);
			if (aTags[i].textContent.toString() == olLabel) {
				//alert('found');
				//aTags[i].style.fontWeight = 'bold';
				aTags[i].innerHTML = newLabel;
				break;
			}
		}

	}, 3000);


}

Output: For Portal

find_real_file.png

 

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@sanvi 

Here you go to make it work for both native + portal

onLoad Catalog Client Script on Your Catalog Item

UI Type - ALL

Isolate Script - False

a) This field is not on form but from list you can make it false

Script:

function onLoad(){

	setTimeout(function(){

		var newLabel = 'My Label';
		var oldLabel = 'My New Label';

		if(window != null){
			$j("span").filter(function() {
				return ($j(this).text() === oldLabel);
			}).html(newLabel);
		}
		else{
			var aTags = this.document.getElementsByClassName("ng-binding");
			var found;
			for (var i = 0; i < aTags.length; i++) {
				if (aTags[i].textContent.toString() == oldLabel) {					
					aTags[i].innerHTML = newLabel;
					break;
				}
			}
		}
	}, 3000);
}

find_real_file.png

Output:

Portal:

find_real_file.png

Native:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader