using business rule, prevents from creating/ updating a new record if a record already existed .

William Dalogdo
Kilo Contributor

Hi, Totally newbie here. I would like to ask how to  prevent creation of a new record, if a record already existed in business rule.   

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not make the u_reference_1 field as Unique at dictionary level?

In this way no business rule is required

In case you still want to use business rule then use this

Before Insert

Script:

var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_reference_1", current.u_reference_1);
gr.query();
if (gr.hasNext()) {   
	gs.addErrorMessage("not allowed");
	current.setAbortAction(true);
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not make the u_reference_1 field as Unique at dictionary level?

In this way no business rule is required

In case you still want to use business rule then use this

Before Insert

Script:

var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_reference_1", current.u_reference_1);
gr.query();
if (gr.hasNext()) {   
	gs.addErrorMessage("not allowed");
	current.setAbortAction(true);
}

Regards
Ankur

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

thank you man. How Brilliant!

Glad to know that it helped.

Please mark response helpful as well.

Regards
Ankur

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