how to write business rule for a particular record producer catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 06:59 AM
Hi Team,
How to write a business rule for a particular record producer?
how to add 3 users in the record watchlist?
How do give the condition that only 3 customers who are in the watchlist, they only receive ticket uperates through emails?
Quick answers will help me to complete the task.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 09:26 AM
Hi @GAyathri33 ,
To write a business rule for a particular record producer catalog form, you can follow these steps:
- Identify the record producer for which you want to create the business rule.
- Navigate to "System Definition" > "Business Rules" in the ServiceNow application.
- Click on "New" to create a new business rule.
- Provide a name and a description for the business rule.
- Set the "Table" field to the table associated with the record producer (e.g., sc_cat_item_producer for catalog items or sc_cat_producer for categories).
- Define the conditions under which the business rule should execute using the "When to Run" field. For example, you can use a condition based on the producer's sys_id or any other field associated with the record producer.
- In the script field, write the script code that should be executed when the business rule conditions are met. This code can include any actions or operations you want to perform for the specific record producer.
- Save the business rule.
To add three users to the record's watchlist, you can use the following code within your business rule:
(function executeRule(current, previous /*null when async*/) {
var watchList = current.watch_list.toString(); // Get the current watchlist as a string
var usersToAdd = ['user1', 'user2', 'user3']; // Replace with the actual user sys_ids or usernames
// Loop through the users to add
for (var i = 0; i < usersToAdd.length; i++) {
var user = usersToAdd[i];
if (watchList.indexOf(user) === -1) {
watchList += ',' + user; // Add the user to the watchlist if not already present
}
}
current.watch_list = watchList; // Update the watchlist field with the modified value
})(current, previous);
Replace 'user1', 'user2', 'user3' with the sys_ids or usernames of the three users you want to add to the watchlist.
To ensure that only the three customers in the watchlist receive ticket updates through emails, you can configure the "Notification" settings in ServiceNow. Specifically, you can modify the notification settings for the relevant table (e.g., the incident table) and the specific events (e.g., update event) to control who receives email notifications.
- Navigate to "System Policy" > "Notifications" > "Email Client Scripts" in the ServiceNow application.
- Find the email client script associated with the table and event you want to modify (e.g., incident table and update event).
- Modify the script to include a condition that checks if the current user is one of the three customers in the watchlist. If the condition is true, proceed with sending the email notification. Otherwise, skip the notification.
Thanks,
Ratnakar