How to hide record from related list when state is "Pending"

Elton2
Tera Contributor

Hi everyone, how are you?!

 

I want to hide a record from a related list when the state is "Pending"
I tried using a UI Policy:

 

Condition:
state is pending (print 1)

I also tried using the Script (print_3):

 

function onCondition() {
 
if(g_form.setValue('state') == '-5'){
g_form.setVisible(false);
}
 
}
 
But the record with the state "Pending" is still in the related list (print_2), but it should be hidden, because
it is not to show the records when the state is "Pending".
 

Could anyone give me a tip or help me?

Thanks!

2 ACCEPTED SOLUTIONS

aKartik
Tera Expert

From what I know so far I don't think there is a way to hide a record in related list but either remove or filter it out.

If you want to remove it you will have to delete the record, you ca take a look at this link below:

https://www.servicenow.com/community/developer-forum/how-to-remove-related-articles-records-from-rel...

 

However I can see the condition of removal is not triggered from the main table but the related list table itself, state changed to pending. For that I would suggest adding a filter in the related list itself and then setting it as default, however it can be easily removed from the breadcrumb by anyone which will remove the filter entirely.

Screenshot 2023-11-03 at 8.55.10 PM.png

 

 If this response clears up your doubt, kindly flag it as both helpful and correct.

Thanks

View solution in original post

A ui policy wont work, you have to create a server side script.

 

You can also change the default filter of the related list, This is also a good option. See this -> https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/use/using-forms/task/t_CreateA...

 

 

-Anurag

View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can write a Query BR or READ ACL to check if this is a related list  using scripted below

 

RP.isRelatedList()

 

Also make sure you check that the parent is is the table you want this to be on 

eg

 

parent.getTableName() == 'incident'

 

 

And return false

 

Something like below

if(RP.isRelatedList() && parent.getTableName == 'incident')
answer = false;

 

-Anurag

Hi @Anurag Tripathi , how are you?!

I appreciate your suggestion, but it didn't work. I have this table (u_project_sa ) that is related to the Incident table, I need it to not be shown when the record is in the "Pending" state. 

 

due to this I tried this script but it is not working:

 

function onCondition() {
 
if(g_form.setValue('state') == '-5'){
g_form.setVisible(false);
}
 
}

A ui policy wont work, you have to create a server side script.

 

You can also change the default filter of the related list, This is also a good option. See this -> https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/use/using-forms/task/t_CreateA...

 

 

-Anurag

Hi @Anurag Tripathi , how are you?!

Thank you so much for your support!

Tks