in Ui Policy when to apply conditions how to identify whther it is new form or an existing from?

vishnu_vandana
Kilo Contributor

we have a requirement to apply ui policy action when the respective ui policy should work only on new form not on existing form.

1 ACCEPTED SOLUTION

sai krishna10
Giga Guru

Yes we can in condition

Place the condition as created by is empty then it will work on new records.

 

If it is new record then the createdby field is empty so the UI Policy will work on new form. when the record is inserted then the ui policy will not work.

 

I tested it in my instance and working fine, Pls let me know if you have any queries.

 

Mark correct or helpful based on the impact.

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vishnu,

In UI policy there is no such method to know whether it is new record or existing record. better move the code to client script and use g_form.isNewRecord()

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

sai krishna10
Giga Guru

Yes we can in condition

Place the condition as created by is empty then it will work on new records.

 

If it is new record then the createdby field is empty so the UI Policy will work on new form. when the record is inserted then the ui policy will not work.

 

I tested it in my instance and working fine, Pls let me know if you have any queries.

 

Mark correct or helpful based on the impact.

Hi Sai,

That is a workaround. For below scenario it will fail if someone updates the record in the table and uses autoSysField(false) while clearing the created by field in this case it is an existing record but since created by is empty UI policy will fail and treat it as new record. So recommended approach would be to use client script on safer side.

var gr = new GlideRecord('incident');
gr.addQuery('sys_id','<sysId>');
gr.autoSysFields(false);
gr.query();
if(gr.next()){

gr.sys_created_by = '';
gr.update();
}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vishnu,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader