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

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

@Elton2 

Mark my answer Helpful & Accepted if I have answered your question

Elton2
Tera Contributor

Hi @aKartik , how are you?!

It's working, I used the filter on the related list (state is not pending). Thank you all for your help!

Thank you!!!

No problem. 🥂