How to write a client script to hide fields from form if created after today date serviceNow?

Community Alums
Not applicable

Hi All,

I want to hide field from for if created after today how to write a client script for this?

Thanks in Advance,

Prachi

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

What's the reason for asking for a Client Script? You could achieve such a condition using zero code: UI Policy.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Community Alums
Not applicable

Hi Mark,

Actually I have tried this with UI policy but its not working on Service Portal form.

Hi Prachi,

Would appreciate if what has been done is shared with us.

I'm a little bit confused by "today". Is the question about comparing a date field with today and hiding a field if the date is after today's date? If the question is about comparing the system assigned "Created" (sys_created_on) date, it would always be false because the "Created" will always be before or on today.

Example of UI Policy to compare a field of type date with today and hiding a field if the date is after today.

1. Created 2 variables as below. Field "Today" will contain a date and Field "Field to hide" will be hidden based on value of field "Today".

find_real_file.png

2. Defined UI Policy as follows:

find_real_file.png

3. Defined Policy action as follows:

find_real_file.png

Execution results:

Case 1: Date is today. Field "Field to hide" is displayed because the condition to hide is "after" today.

find_real_file.png

Case 2: Date is tomorrow. Field "Field to hide" is hidden.

find_real_file.png

Community Alums
Not applicable

Hi Hitoshi,

Thank you for your reply, my query is I don't want to show one field in future cases. The field should be visible on all past cases but it should be hidden from tomorrow in all future cases.

To achieve this I was writing UI policy on Created field  but it is not working.  

find_real_file.png