getReference is not working in client script

sriram7
Tera Contributor

Hi Team,

 

getReference is now working, below is my code.

 

Code is for hide buyer group variable when requested for company is Cubis Industries UK, Ireland & France.

 

function onLoad() {
    // Type appropriate comment here, and begin script below
   var requestedFor = g_form.getReference('request_for', hideField);
alert(requestedFor);
 
 
function hideField(requestedFor) {
   // if (requestedFor && requestedFor.company) {
        var requestedForCompany = requestedFor.company.getDisplayValue();
        
        alert(requestedForCompany);
        
        if (requestedForCompany == 'Cubis Industries UK, Ireland & France') {
            g_form.setDisplay('buyer_groups', false);
       // }
    }
}
}
 
1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Sriram,

Try below

function onLoad() {
    // Type appropriate comment here, and begin script below
   var requestedFor = g_form.getReference('request_for', hideField);
alert(requestedFor);
 
 
function hideField(requestedFor) {

        var requestedForCompany = requestedFor.company;//this will give sys_id of company
        
        alert(requestedForCompany);
        
        if (requestedForCompany == 'Cubis Industries UK, Ireland & France') { //pass sys_id instead of name for Cubis Industries
            g_form.setDisplay('buyer_groups', false);
    }
    }

}

View solution in original post

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

Hi Sriram,

Try below

function onLoad() {
    // Type appropriate comment here, and begin script below
   var requestedFor = g_form.getReference('request_for', hideField);
alert(requestedFor);
 
 
function hideField(requestedFor) {

        var requestedForCompany = requestedFor.company;//this will give sys_id of company
        
        alert(requestedForCompany);
        
        if (requestedForCompany == 'Cubis Industries UK, Ireland & France') { //pass sys_id instead of name for Cubis Industries
            g_form.setDisplay('buyer_groups', false);
    }
    }

}

manjusha_
Kilo Sage

@sriram7 

 

Instead of using getreference you can use script include 

Servicenow does not recommend getReference 

 

Thanks,

Manjusha Bangale