Need business rule to only create record if one doesn't already exist

wade88761
Kilo Contributor

I have a before Business Rule setup to create a record in a custom application whenever an incident is submitted. It works fine but I want to add in a part that says it will only create the record if there hasn't already been a record created in the table for the customer. The field in the table that I want it to check against is u_customer. To clarify, if there is already a record for 'u_customer' in the "u_admin_survey" table then don't run the business rule.

(function executeRule(current, previous /*null when async*/) {

var survey = new GlideRecord("u_admin_survey");

  survey.initialize();

  survey.u_incident = current.sys_id;

  survey.u_customer = current.u_on_behalf_of;

  survey.u_ticket_type = "Incident";

  survey.u_customer_phone = current.u_on_behalf_of.phone;

  survey.insert();

})(current, previous);

1 ACCEPTED SOLUTION

venkatiyer1
Giga Guru

(function executeRule(current, previous /*null when async*/) {


var survey = new GlideRecord("u_admin_survey");


// check whether it exists below will return null if not present


if(!survey.get("u_customer_phone", current.u_on_behalf_of.phone )) {


  survey.initialize();


  survey.u_incident = current.sys_id;


  survey.u_customer = current.u_on_behalf_of;


  survey.u_ticket_type = "Incident";


  survey.u_customer_phone = current.u_on_behalf_of.phone;


  survey.insert();


}  


})(current, previous);


View solution in original post

5 REPLIES 5

venkatiyer1
Giga Guru

(function executeRule(current, previous /*null when async*/) {


var survey = new GlideRecord("u_admin_survey");


// check whether it exists below will return null if not present


if(!survey.get("u_customer_phone", current.u_on_behalf_of.phone )) {


  survey.initialize();


  survey.u_incident = current.sys_id;


  survey.u_customer = current.u_on_behalf_of;


  survey.u_ticket_type = "Incident";


  survey.u_customer_phone = current.u_on_behalf_of.phone;


  survey.insert();


}  


})(current, previous);


Thanks for the help, Realized after thinking that records that have a status of "Answered" will be stored in this table so I need to add a way to NOT create a record if there is a record already in the table with a Status of "New" for the customer.


venkatiyer1
Giga Guru

Sure,   then you can easily add that condition to the business rule itself


The business rule is running off the Incident table though. I just want the business rule to not run whenever there is a record in the u_admin_survey table for the u_customer and that record has a status of "New".