Issue with g_form.getControl() in Client Script

Service now11
Tera Contributor

Hi,

 

I have a "satge" field that I want to highlight with a red background when the value is "waiting_for_approval". The script works fine in the instance but not in the Service Portal. Can anyone suggest an alternative approach to achieve this in the Service Portal?

 

function onLoad() {  
    var stage = g_form.getValue('stage');
     if (stage === 'waiting_for_approval') {
        var message1 = '** CAUTION** Ticket is awaiting approval. Do NOT fulfill/handle (yet) UNLESS manual approval has been achieved and documented in the Work notes.';
        var message2 = message1.fontcolor("white");
        g_form.addErrorMessage('<span style="background-color: red; font-weight: bold; padding: 5px;">' + message2 + '</span>');
       g_form.setReadOnly('stage', true);
         var stageLabel = g_form.getControl('stage');
        stageLabel.style.backgroundColor = "red";
        stageLabel.style.fontWeight = "bold";  
    }
}
 
Thanks

 

7 REPLIES 7

@Service now11 

this is normal form? if yes then for RITM table?

if it's a form then you will have to create your own form widget and add custom code to it, somewhat not good for maintenance

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

@Service now11 

Hope you are doing good.

Did my reply answer your question?

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

@Service now11 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

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