- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 09:35 AM
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);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 09:45 AM
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 09:45 AM
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 12:28 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 12:31 PM
Sure, then you can easily add that condition to the business rule itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 12:43 PM
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".