Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 01:26 AM
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);
// }
}
}
}
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 01:31 AM
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);
}
}
}
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 01:31 AM
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);
}
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 02:00 AM
Instead of using getreference you can use script include
Servicenow does not recommend getReference
Thanks,
Manjusha Bangale