Catalog Client Script to change display label value?

MBarrott
Mega Sage

I have an onChange Catalog Client Script which is checking for change to a name field. 

 

I would like to then have this name display within the display value variable I have on the form. 

 

I've tried g_form.setValue('display_var', newValue); and g_form.setLabelOf('display_var', newValue); but neither have updated the display label. 

 

What's the scripting solution to this?

1 ACCEPTED SOLUTION

MBarrott
Mega Sage

For anyone curious I did some digging and ServiceNow specify that this actually shouldn't be possible and is expected behavior. 

 

This has been addressed on KB0758098: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0758098

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@MBarrott 

this should work. Did it not run in native or portal? Is that variable name correct?

Please share the complete script along with screenshots.

g_form.setLabelOf('display_var', newValue);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar,

 

Running it in Service Portal. Variable names are correct. 

 

Script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') 
   {
      return;
   }
	alert(newValue);
	
   //Type appropriate comment here, and begin script below
   g_form.setLabelOf('emp_agreement', newValue);
}

MBarrott_0-1741628278516.png

 

 

@MBarrott 
Could you please use the solution on:

https://www.servicenow.com/community/developer-forum/set-variable-label-in-service-portal/m-p/204854...

“Actually this solved it...for both the ITIL Service Catalog and the Service Portal:

 

MediC_0-1741629033297.png

 

Here is the UI Script function:

 

MediC_1-1741629033298.png

 

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Hi @Medi C - I did find this and the solution shown would suggest I'm already doing that (setLabelOf)