Why setDisplay() method is not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 12:58 AM
The below client script is for service portal in which setDisplay() method is not working.
Could anyone please help?
Thanks,
Ankita
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 01:18 AM
function onLoad(){
if(g_form.getValue('u_source') == 'others'){
alert('true');
g_form.setVisible('u_new_source', true);
}
else{
alert('false');
g_form.setMandatory('u_new_source', true);
g_form.setVisible('u_new_source', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 09:46 PM
Hi Willem,
Still it's not working.
Thanks,
Ankita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 09:53 PM
You want to show the field only if u_source is others right?
You should use this:
function onLoad(){
if(g_form.getValue('u_source') == 'others'){
alert('true');
g_form.setMandatory('u_new_source', true);
g_form.setVisible('u_new_source', true);
}
else{
alert('false');
g_form.setMandatory('u_new_source', false);
g_form.setVisible('u_new_source', false);
}
}
You cannot set a mandatory field to not be visible. So you have to make it not mandatory first.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 10:08 PM
Hi Ankita,
The script you have added in question is right just few changes required there.
Updated script.
function onLoad(){
if(g_form.getValue('u_source') == 'others'){
alert('true');
g_form.setVisible('u_new_source', true);
}
else{
alert('false');
g_form.setMandatory('u_new_source', false);
g_form.setVisible('u_new_source', false);
}
}
Note - changes are in bold.
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 01:13 AM
Hi,
In addition to above, You can use
g_form.setVisible('u_source',true);
g_form.setVisible('u_source',false);
Thanks,
Dhananjay.