- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 03:59 PM
How do I create a UI Policy that executes only if the record already exists (i.e. !g_form.isNewRecord())?
I want assignment_group to be mandatory if the record exists, but not mandatory if the record does not exist (because a new record will have assignment_group populated by an Assignment Rule).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 12:13 AM
The test for sys_id = -1 did not work. However, what did work was a test for Created Is Empty.
This UI Policy makes Assignment group mandatory only if the the record already exists:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 07:31 PM
Hey,
I think you have answered yourself, you can use "g_form.isNewRecord()" if you want to apply a logic when a record is new.
One other way that I could think of is to have condition checkas sys_id = -1, so as we know, before a record is created, the sys_id remains as -1, then you can make the field non-mandatory for this condition.
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 08:32 PM
Hi Giles,
UI Policy does not have feature to run script on condition.
Instead of using UI Policy, how about writing Client Script.
function onLoad() {
if (!g_form.isNewRecord()) {
g_form.setMandatory('assignment_group', true);
} else {
g_form.setMandatory('assignment_group', false);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 12:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 12:23 AM
Hi,
just add this in the condition field and it would work only for existing records
Created by [IS NOT] EMPTY
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader