'OR' operator not working in Client Script

taylor11
Giga Contributor

Hi all! 

I am trying to only show the sc_task related list on sc_req_item forms when the item is (this || that). The script is working when I remove the or condition and only have the one condition in the 'if' statement but when I add the || to the script, it doesn't work for either of the two items that I am trying to show the related list on. Here is my script: 

find_real_file.png

 

Any feedback would be greatly appreciated! I have also tried the if statement like this: 

function onLoad() {

var item = g_form.getValue('cat_item');

if (item != '//sys_id of item 1' || item != '//sys_id of item 2'){
  g_form.hideRelatedList('sc_task.request_item');
}

}
1 ACCEPTED SOLUTION

Jay81
Tera Guru

Please try below script.

 

var item = g_form.getValue('cat_item');


//alert(item);

if ((item == 'sysid') || (item == 'sysid')) {
g_form.showRelatedList('sc_task.request_item');

}
else
{
g_form.hideRelatedList('sc_task.request_item')
}

View solution in original post

7 REPLIES 7

Are the Catalog Tasks automatically created by a business rule or workflow?  If so, it might be a better idea to modify the List Control to hide the related list if there are no catalog tasks.  This way, you won't need to go back and modify your client script each time you want the related list to appear for more items.

 

find_real_file.png

 

This method won't work if these Catalog Tasks are created manually by your users, however.

Jay81
Tera Guru

Please try below script.

 

var item = g_form.getValue('cat_item');


//alert(item);

if ((item == 'sysid') || (item == 'sysid')) {
g_form.showRelatedList('sc_task.request_item');

}
else
{
g_form.hideRelatedList('sc_task.request_item')
}

taylor11
Giga Contributor

Beautiful! Thank you so much. This works perfectly. 🙂