Difference between UI policy and Client script

Ananya Venkat
Tera Contributor

Hello!

 

When we need to make a field mandatory, in the initial state we can do it using client script and UI Policy

 

Client script: (on load)

if (g_form.isNewRecord()) {
g_form.setMandatory('u_field', true);

 

Ui policy:

condition --> state is new

ui policy action --> u_field mandatory true

 

1)What is the difference between these two? Do they both give same result exactly? if not what is different?

2)Which one is preferrable and why?

 

Thanks,

Ananya.

1 ACCEPTED SOLUTION

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Both are different

1) Client script : g_form.isNewRecord() will run only if form is not yet submitted and record is new and yet to be created. Once record is created it will not run again

2) UI policy : Will always run if condition is satisfied irrespective even when record is not submitted and even after loading of newly created record. It will always run on load if condition is satisfied

 

What to use ?

Depends on your requirement , if you want to do certain validation on load before record is created then use your client script otherwise use UI policy. If requirement is same and can be done with UI policy and client script then go for UI policy

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

2 REPLIES 2

Aman Kumar S
Kilo Patron

Client script and UI policy can be used interchangeably, but client script runs before UI policies.

UI policies are used for setting fields mandatory, read only and visible and Client script is used for more complex requirements, where you need to lookup and populate fields, basically requiring scripting.

Talking about the script, the client script would set the field as true when the form loads for the first time.
The UI policy would set the field as true when state is new and would if false, if "reverse if true" checkbox is marked as true in the UI policy form, else it would remain true.

Best Regards
Aman Kumar

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Both are different

1) Client script : g_form.isNewRecord() will run only if form is not yet submitted and record is new and yet to be created. Once record is created it will not run again

2) UI policy : Will always run if condition is satisfied irrespective even when record is not submitted and even after loading of newly created record. It will always run on load if condition is satisfied

 

What to use ?

Depends on your requirement , if you want to do certain validation on load before record is created then use your client script otherwise use UI policy. If requirement is same and can be done with UI policy and client script then go for UI policy

 

Please hit like and mark my response as correct if that helps
Regards,
Musab