Before buisines rule

krishna_1B
Tera Contributor

Can delete a record in incident table once we set the impact,urgent,priority to 1 
Like can we write a script in Before BR for both creating inc with priority high and after creating it can we delete it using same BR ?

7 REPLIES 7

Nikhil Bajaj9
Tera Sage

Hi @krishna_1B ,

 

No it is not possible with Before business Rule but what is your use case?

 

If my answer helped you, please mark it - Solution accepted. 

 

Regards,

Nikhil Bajaj

Rafael Batistot
Mega Patron

Hi @krishna_1B 

 

There is a safe approach for you require 

 

Instead of allowing the record to be created and then deleting it, you can stop the record from ever being created in the first place.

 

May you handle using a Before > Insert Business Rule 


Code: 

if (current.operation() == 'insert' && current.impact == 1 && current.urgency == 1 && current.priority == 1) {
gs.addErrorMessage("Incidents with Priority 1 cannot be created.");
current.setAbortAction(true); // stop the insert
}

AndersBGS
Tera Patron

Hi @krishna_1B ,

 

 what is the context? what is the business requirement? Your question is quite confusing.

 

Bhuvan
Giga Patron

@krishna_1B 

 

Answer is NO. Before BR are run before a record is inserted to the database. If you create a before BR to update the Impact, Urgency and Priority to 1 but not completing the DB operation and trying to delete the record, it will not be recorded in the database. You should always validate business requirements and whether it would help optimize your processes before scripting. Even if something is possible in scripts, you should always think from best practices perspective and long-term impact & the justification for creating a custom script in the first place.

 

Business Rules are server-side scripts that performs database operations when a record is inserted/updated/deleted/queries. 'When' is a choice field in BR and dictates when it should execute before/after/async/display.

Bhuvan_0-1755995387913.png

You can find more information from below link,

 

https://developer.servicenow.com/dev.do#!/learn/learning-plans/zurich/new_to_servicenow/app_store_le...

 

https://developer.servicenow.com/dev.do#!/learn/learning-plans/zurich/new_to_servicenow/app_store_le...

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan