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

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

Ravi9
ServiceNow Employee
You can read about setabort in sn doc

thank you.

emir
ServiceNow Employee

Your form makes no sense as it is. If they select a user here, then a user exists, so no need for something like this.

You need some unique identifier for new users such as email, id, etc. For example, they type in emir or emir@now.com and then you query the user table to see if user with that id exits, if not let them create one.

I hope this makes sense.

Hi Emir. Thank you for your response! Actually, this is only practice exercise given by my instructor. I really cant figure out how to write a script for this one. should I use glide record or gs ?