Label Variable Set Value (Service Portal)?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 05:57 PM
I have a Label type variable in a catalog item that I'm displaying through Service Portal.
I want to set the text of the label (called "change_window") through an onLoad Catalog Client Script.
I've tried g_form.setValue("change_window", "Whatever") and g_form.setLabelOf("change_window", "Whatever") but neither of those work (though they work fine for text fields).
Can anyone tell me how to set the text of the label?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 12:26 PM
Patrick hope this helps you...I did get this working in the backend and in the Service Portal:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var typeofrequest = g_form.getValue('type_of_request');
if(typeofrequest == 'position_change'){
g_form.setLabelOf('job_function','New Job Function'); //Works in Service Portal
changeFieldLabel('job_function','New Job Function'); // Works in ITIL Service Catalog
}else{
g_form.setLabelOf('job_function','Job Function');
changeFieldLabel('job_function','Job Function');
}
}
function changeFieldLabel(field, label, color, weight){
try{
var labelElement = $('label_' + g_form.getControl('job_function').id);
labelElement.select('.sn-tooltip-basic').each(function(elmt) {
elmt.innerHTML = label;
if(color)
elmt.style.color = color;
if(weight)
elmt.style.fontWeight = weight;
});
}catch(e){}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 01:24 PM
That's excellent Steven! just punched it in and works perfectly...thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 02:03 PM
Hi again Steven,
got a question about your experience with multiple functions in the same onChange catalog client script. I've got several variations of GlideAjax and other field logic (including this new bit from you about setting a variable question)...if all this logic is being driven by the same variable, is it best (or possible) to have all the functions in one onChange catalog client script? Or do I break these up into several running off the same variable? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 05:53 AM
Hi Patrick,
I know this date a bit, but if you see it then what I would do is to put all your functions like the "changeFieldLabel" in a empty onLoad type script that I would call something like "Utility Functions". By "empty onLoad script" I mean I would get rid of the onLoad function definition (or use it to initialize global form stuff if you have a use for it).
That way, all you other scripts can refer to this function as a library for the form and you know where all those functions are located...