- 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 01:40 PM
(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.state == "New")) {
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);
The above should work but just ensure the column name is state or else feel free to change it accordingly