- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 06:45 AM
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:
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');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 07:46 AM
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')
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 06:48 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 06:55 AM
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');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 06:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 07:00 AM
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.