OnLoad Client Script g_form.setLabelOf

Cobee
Tera Expert

Hello, 

 

I am looking to dynamically update a field label on a form based on the values in a the sys_class_name on alm_asset table using Onload Client script. as per my example below, if the sys_class_name is Kittens, I would like to update the serial_number field label to Cats. I was successful is using this same idea using the state field, But then I could reference the actual value of the choice selected. Not sure if this is possible on the sys_class_name option. 

 

 

Thanks, 

function onLoad() {
//Type appropriate comment here, and begin script below

var type = g_form.getValue('sys_class_name');
if (type == "Kittens"){
g_form.setLabelOf('serial_number', 'Cats');
}
}

14 REPLIES 14

Hi @Cobee,

As a best practice, you have to use the Dictionary approach shared by me & @Alex Coope - SN.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Ok. so on alm_asset table I am looking to have the label for "Serial Number" display as "Cereal Number" when the sys_class_name = Captain Crunch, else display as "Serial Number". 

@Cobee,

But what's the process / business need for that?

Sometimes we have to evaluate that just because we can do something, it might not be the best thing to do if we do it and weighing up the pro vs con of the action is just as important,


(update) - if it's just to do it for something like a hackathon, then what you should do is extend [alm_asset] so you have an extended table of [alm_asset_cereals] then create a label in [sys_documentation] for that table's "element" of "serial number" to be "Cereal Number". That would be the best practice approach,

Many thanks,
kind regards 

--------------------------------------------------------------------
Director of Globalization Deployment, Internationalization

Cobee
Tera Expert

Thanks for the guidance here Alex and Sagar. Much appreciated. 

Hi @Cobee,

 It would be helpful for future readers, if you mark it as correct answer.

 

Thanks,
Sagar Pagar

The world works with ServiceNow