'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

Chuck Tomasi
Tera Patron

Debug tips:

Have you checked your console log for errors?

You could try using g_form.addInfoMessage() as a debug to ensure the value of your item variable and make sure it is what you expect it to be before going in to the if block.

Chuck Tomasi
Tera Patron

The issue is with the logic... This is a little confusing. Don't you want to hide the related list IF it is one of those...?

 

I would rewrite as this for readability:

 

if (item == 'sys_id_1' || item == 'sys_id_2') {

   g_form.hideRelatedList('sc_task.request_item');

}

Chuck Tomasi
Tera Patron

I'm curious why you have a related list of request items on the (sc) task form... Normally the request item is a parent of one or more tasks. Adding a related list of request items seems a bit confusing. Clearly, I don't understand the process, but it appears to be a little non standard by allow multiple request items to be associated with a single task.

Hi Chuck, I would like to only SHOW if it IS one of those items.

I added the g_form.addInfoMessage() into my if statement and the message is showing for all items.

I also changed the != to == and changed g_form.hideRelatedList('sc_task.request_item'); to g_form.showRelatedList('sc_task.request_item');. The related list is showing for all items. 

Here is a screenshot to help clear up what I am trying to do.