How to hide a Related Tab and sections from the RITM form using a UI Policy script.

kjain
Giga Expert

How to hide a Related Tab and sections  from the RITM form using a UI Policy script.

when a particular catalog item is used, the the RITM generated should hide few of the fields, sections and related list and tabs on the form.

find_real_file.png

 

 I have written the code like below in UI Policy Run script

function onCondition() {
g_form.setDisplay('request', false);
g_form.setDisplay('location', false);
g_form.setDisplay('cmdb_ci', false);
g_form.setDisplay('priority', false);
g_form.setDisplay('u_ritm_category', false);

g_form.hideRelatedList('u_vendor_id_reference', true);
//g_form.setDisplay('u_vendor_id_reference', false);

 

Thanks!

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@kjain 

the correct syntax to hide/show section and related list is below

g_form.setSectionDisplay('schedule', false); // name of section

g_form.showRelatedList('task_ci'); // name of related list

g_form.hideRelatedList('task_ci'); // name of related list

check below links for help

Show/Hide Form Section by Name

Hiding Related Lists and Embedded Lists

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

27 REPLIES 27

Hi,

So which are hiding now and which aren't.

please compare the names are proper and whether those related list are actually present on the form via configure related list

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Affected CI, Task SLA, Requested Items and Approvers are not working.

find_real_file.pngThanks!

Hi,

please check any other browser console error?

If it worked fine in your instance then please add alert after every line and you will know where script is breaking

if (g_form.getValue('cat_item') == 'sys_id')
{
g_form.setDisplay('request', false);
//g_form.setDisplay('location', false);
g_form.setDisplay('cmdb_ci', false);
//g_form.setDisplay('priority', false);
//g_form.setDisplay('u_ritm_category', false);
g_form.setDisplay('u_created_by_servicedesk', false);
g_form.setDisplay('u_left_from_servicedesk', false);
g_form.setDisplay('u_request_type', false);
g_form.setDisplay('opened_by',false);
g_form.setDisplay('u_owner', false);
g_form.setDisplay('u_business_process', false);
g_form.setDisplay('u_delivery_approval', false);
g_form.setDisplay('approval', false);
g_form.setSectionDisplay('manual_approval', false);
g_form.setSectionDisplay('related_records', false);

alert('before hiding incident');
g_form.hideRelatedList('incident'); // name of related list

alert('before hiding problem');
g_form.hideRelatedList('problem');

alert('before hiding change request');
g_form.hideRelatedList('change_request');

alert('before hiding RITM');
g_form.hideReleatedList('sc_req_item');

alert('before hiding task sla');
g_form.hideRelatedList('task_sla');

alert('before hiding task ci');
g_form.hideRelatedList('task_ci');

alert('before hiding approval');
g_form.hideRelatedList('sysapproval_approver');

}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@kjain 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate answer as correct & helpful to close the thread.

If not, please let us know if you need some more assistance.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

I moved few lines of the code up and then it is working for all except the related list "Requested Item"

Also when using a UI policy/Client script when loading the form it initially displays all the fields and after fraction of seconds hides the fields etc which is mentioned in the UI policy or Client script.

Do you know why does this happen?

Thanks!

Komal