- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:34 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:42 AM - edited 10-18-2022 07:44 AM
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
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:40 AM
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.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:42 AM - edited 10-18-2022 07:44 AM
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
Regards,
Musab