Can a field be hidden when creating a new record with a script in the UI policy?

Community Alums
Not applicable

Hiii 

I need to hide a field when a new record is created (in the other cases it has to be shown). And I want to avoid doing a client script. So I need to know if I can make a script in an UI Policy to do this. I understand that newRecord() cannot be used in the UI Policy, and I also tried "Created by is Empty" and "Created is Empty" but it doesn't work. Any ideas?

1 ACCEPTED SOLUTION

johnfeist
Mega Sage
Mega Sage

Hi Rocio,

You can do it with a script in either a UI Policy or a script include.  You need to use the isNewRecord() function.  Something like this:

if (g_form.isNewRecord() {
   g_form.setVisible("<your field>", false);
}
else {
   g_form.setVisible("<your field>", true);
}

Remember if you the field you are hiding is also set to mandatory you need to turn that off before setting visible to false.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

View solution in original post

4 REPLIES 4

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Rocio,

You can use a Client script and validate g_form.isNewRecord(). 
Or you can validate if sys_id is different from -1 (records that are not yet saved have sys_id = -1, that is always a way to check if it is a new record).

 

Hope this helps!!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

johnfeist
Mega Sage
Mega Sage

Hi Rocio,

You can do it with a script in either a UI Policy or a script include.  You need to use the isNewRecord() function.  Something like this:

if (g_form.isNewRecord() {
   g_form.setVisible("<your field>", false);
}
else {
   g_form.setVisible("<your field>", true);
}

Remember if you the field you are hiding is also set to mandatory you need to turn that off before setting visible to false.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

it's hiding the field but still gap is there in the form where that field was.

 

Yes, if you use g_form.setVisible(), it hides the field but retains its space in the form layout. If you want to remove the field completely, including its space, you should use g_form.setDisplay('field_name', false);. This will not only hide the field but also remove the gap it occupies.