getElementsByClassName

sowmya29
Tera Contributor

Hi All.,

getElementsByClassName ( on load client script) is not working in service portal. how to replace or any other ideas?

Checked on Isloate script and it is set to be false.

Regards,

Sowmiya

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sowmya,

you need to try to update isolate script as false; this field is available in list layout of the catalog client script and not on form; Also set UI type as ALL

find_real_file.png

can you share what script you are performing?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi AnKur.,

Isolate script was set to false but even then it is not working

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

var isNew = g_form.isNewRecord();

var work_notes_hint = 'Can be used to document updates/changes to the Change throughout the lifecycle. This can include date changes, changes to scope (i.e. removal or addition of content), or any other relevant information that should be documented on the change.';

var labels = document.getElementsByClassName("control-label");

if(!isNew){
for(var i=0;i<labels.length;i++){
if(labels[i].innerHTML.indexOf('Work notes')> -1)
labels[i].title=work_notes_hint;
}
}
else{
for(var j=0;j<labels.length;j++){
if(labels[j].getElementsByTagName('span')[1].innerHTML.indexOf('Work notes') > -1)
labels[j].getElementsByTagName('span')[1].title=work_notes_hint;
}
}
}

Hi,

what are you trying to achieve using above script? I could see the field hint is being changed

Regards
Ankur

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

Hi Ankur.,

i m just adding work notes hint for the change.

var labels = document.getElementsByClassName("control-label"); this line only getting an error in service portal.

js_includes_sp.jsx?v=12-2019_1137&lp=Mon_Nov_18_05_25_00_PST_2019&c=8_111:39978 (g_env) [SCRIPT:EXEC] Error while running Client Script "set Work notes Hint": TypeError: Cannot read property 'getElementsByClassName' of null

Regards,

Sowmiya