- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 03:08 AM - edited 06-24-2024 04:23 AM
Hi folks,
I have a requirement that to create a notification for a catalog item after 2 hours of sctask creation send to requested for. And if the requested for replies to the email they want to copy the reply to the comments on sctask
Please anyone will let me know how to do that the steps? @Ankur Bawiskar @Anurag Tripathi @Anil Lande @suvro
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 04:59 AM
Hi @Priyanka Chaud1 ,Based on your requirement I've gathered a solution, Try this and see if it helps. You might have to modify it a little bit:
Here are the steps to create a notification for a catalog item after 2 hours of sc_task creation and to copy email replies to the comments on sc_task:
1: Create a Scheduled Job for the Notification
Go to System Definition > Scheduled Jobs.
Click on "New".
Fill out the form:
Name: Give your scheduled job a name, e.g., "Notify Requested For after 2 hours of sc_task creation".
Run: Set this to "Periodically".
Interval: Set the interval to 2 hours.
Condition: Use a condition that selects sc_task records created in the last 2 hours.
Write a script to find the appropriate sc_task records and send the notification.
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('sys_created_onONLast 2 hours@javascript:gs.beginningOfLast2Hours()@javascript:gs.endOfLast2Hours()');
gr.query();
while (gr.next()) {
var notify = new GlideEmailOutbound();
notify.setSubject('Reminder: Catalog Task');
notify.setBody('This is a reminder that you have a catalog task created.');
notify.setFrom('your_email@domain.com');
notify.setTo(gr.requested_for.email);
notify.send();
}
2: Set Up Inbound Email Actions
Go to System Policy > Inbound Actions.
Click on "New".
Fill out the form:
Name: Provide a name like "Reply to sc_task comments".
Target Table: Select "sc_task".
Type: Select "Reply".
Active: Check this box to make sure it’s enabled.
Write a script to add the email reply to the comments field of the sc_task.
// Assuming email body contains the comment
var gr = new GlideRecord('sc_task');
gr.get(current.target.sys_id);
if (gr.isValidRecord()) {
gr.comments = email.body_text;
gr.update();
}
3: Configure Email Notification
Go to System Notification > Email > Notifications.
Click on "New".
Fill out the form:
Name: Provide a name for the notification.
Table: Select sc_task.
When to send: Select "Event is fired".
Event name: Create a new event or use an existing one.
Who will receive: Add the "Requested for" field.
What it will contain: Create your email template and message content.
4: Create a Business Rule to Trigger Event
Go to System Definition > Business Rules.
Click on "New".
Fill out the form:
Name: Provide a name for the business rule.
Table: Select sc_task.
When: After.
Update Condition: Your condition for sending the notification, for example, 2 hours after creation.
Script:
Use a script to trigger the event after 2 hours.
(function executeRule(current, previous /*null when async*/) {
gs.setEvent('sc_task.2hour.notification', current, current.sys_id);
})(current, previous);
Explanation
- Scheduled Job: To run a job periodically to check for sc_task created in the last 2 hours and send notifications.
- Inbound Email Action: To handle email replies and add them to sc_task comments.
- Email Notification: Configure the email notification to be sent based on your event.
- Business Rule: To trigger an event after 2 hours to send the notification.
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 04:59 AM
Hi @Priyanka Chaud1 ,Based on your requirement I've gathered a solution, Try this and see if it helps. You might have to modify it a little bit:
Here are the steps to create a notification for a catalog item after 2 hours of sc_task creation and to copy email replies to the comments on sc_task:
1: Create a Scheduled Job for the Notification
Go to System Definition > Scheduled Jobs.
Click on "New".
Fill out the form:
Name: Give your scheduled job a name, e.g., "Notify Requested For after 2 hours of sc_task creation".
Run: Set this to "Periodically".
Interval: Set the interval to 2 hours.
Condition: Use a condition that selects sc_task records created in the last 2 hours.
Write a script to find the appropriate sc_task records and send the notification.
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('sys_created_onONLast 2 hours@javascript:gs.beginningOfLast2Hours()@javascript:gs.endOfLast2Hours()');
gr.query();
while (gr.next()) {
var notify = new GlideEmailOutbound();
notify.setSubject('Reminder: Catalog Task');
notify.setBody('This is a reminder that you have a catalog task created.');
notify.setFrom('your_email@domain.com');
notify.setTo(gr.requested_for.email);
notify.send();
}
2: Set Up Inbound Email Actions
Go to System Policy > Inbound Actions.
Click on "New".
Fill out the form:
Name: Provide a name like "Reply to sc_task comments".
Target Table: Select "sc_task".
Type: Select "Reply".
Active: Check this box to make sure it’s enabled.
Write a script to add the email reply to the comments field of the sc_task.
// Assuming email body contains the comment
var gr = new GlideRecord('sc_task');
gr.get(current.target.sys_id);
if (gr.isValidRecord()) {
gr.comments = email.body_text;
gr.update();
}
3: Configure Email Notification
Go to System Notification > Email > Notifications.
Click on "New".
Fill out the form:
Name: Provide a name for the notification.
Table: Select sc_task.
When to send: Select "Event is fired".
Event name: Create a new event or use an existing one.
Who will receive: Add the "Requested for" field.
What it will contain: Create your email template and message content.
4: Create a Business Rule to Trigger Event
Go to System Definition > Business Rules.
Click on "New".
Fill out the form:
Name: Provide a name for the business rule.
Table: Select sc_task.
When: After.
Update Condition: Your condition for sending the notification, for example, 2 hours after creation.
Script:
Use a script to trigger the event after 2 hours.
(function executeRule(current, previous /*null when async*/) {
gs.setEvent('sc_task.2hour.notification', current, current.sys_id);
})(current, previous);
Explanation
- Scheduled Job: To run a job periodically to check for sc_task created in the last 2 hours and send notifications.
- Inbound Email Action: To handle email replies and add them to sc_task comments.
- Email Notification: Configure the email notification to be sent based on your event.
- Business Rule: To trigger an event after 2 hours to send the notification.
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 05:39 AM
Hey @HrishabhKumar Thank you so much for such a detailed explanation really appreciated! I have a question on this that we are using flow for the particular catalog item(as requirement is only for this item) so we have wait duration condition in flow can we use that instead of schedule job? Also if we are using flow can you let me know how that will work I mean ill create notification call that in flow? And how copy comments to sc_task the same inbound email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 01:50 AM
Hi @Priyanka Chaud1 ,
Use the "Name" field in the sc_cat_item table, to filter out the items related to your particular catalog item.
You can use flow as well. Try to get the logic of the solution, and try to implement the same in flow. You can add screenshot o your flow, if t did not work.
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 02:57 AM - edited 06-27-2024 07:37 AM
Hi @HrishabhKumar so i created a notification on sc_task table kept when to run trigerred and sending it to requested for and used that in flow (attached the screenshot) and i checked after sc_task creation its sending the notification. Now my further requirement is if If the requested for replies to the email notification, add the response as an additional comment and do not close the task and if no response till 2 days close the task..can you help me with this please @Ankur Bawiskar @Anil Lande @suvro @Anurag Tripathi