Why setLabelOf() function is not allowing below code to run in the onload script?

Apoorva A H
Tera Contributor

Hii All,

My question is about related to the setLabelOf() function, As i came across that i have used setLabelof() for one field to relabel it then it worked but below code was not running then i commented the code of setLabelof() then below code was running fine, Can i know what is the reason why it is happening like that?

6 REPLIES 6

Community Alums
Not applicable

Hi @Apoorva A H ,

 

I tried your problem in my PDI and it works for me please use below script

function onLoad() {
    //Type appropriate comment here, and begin script below
	changeFieldLabel('description', 'My New Label', 'red', 'bold');
}

function changeFieldLabel(field, label, color, weight) {
    try {
        var labelElement = $('label_' + g_form.getControl(field).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) {}
}

SarthakKashyap_1-1725865718753.png

Set isolate script to false

 

 

 

Result 

SarthakKashyap_2-1725865739600.png

 

 

Also check 

SarthakKashyap_0-1725865244528.png

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

No my question is not about why setlabelof is not working. actually setlabelof is working fine but below code whatever we have written after setlabelof that is not working but if we comment the code of setlabelof then below code works. so what is the reason behind that?

 

Community Alums
Not applicable

@Apoorva A H ,

Can you paste your code below

ya sure but basically this is written onload for request view,

 g_form.setLabelOf('field name', "label name");

 if (viewname == 'view_name') {

        g_form.setDisplay("fieldname1", true);

        g_form.setDisplay('fieldname2', true);

    }

for the above following code so in my thing i want to display the two fields for HR partner for the view so i added below the code of setlabelof() then setlabel is changing the label but for the view it is not displaying these two fields. So i commented the first line then it is displaying the 2 fields.