UI Policy only if record already exists

GLewis5
Tera Guru

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).

1 ACCEPTED SOLUTION

Giles Lewis
Tera Guru

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:

find_real_file.png

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

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 🙂

Hitoshi Ozawa
Giga Sage

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);
    }
}

Giles Lewis
Tera Guru

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:

find_real_file.png

Ankur Bawiskar
Tera Patron

Hi,

just add this in the condition field and it would work only for existing records

Created by [IS NOT] EMPTY

Regards
Ankur