UI Action button development

Awantika verma
Tera Contributor

I need to develop a UI action button in CSM workspace which will send reminder when pressed   to last email sent to person. Need help in step by step in configuring action button in CSM workspace and the script which will extract the last email sent to person and then send reminder notification to the current case.

9 REPLIES 9

Sindhup
Tera Contributor
  • To configure a UI action button in CSM Workspace to send a reminder email for the last email sent, follow these steps:

     

    Step 1: Create the UI Action

     

    1. Navigate to UI Actions: Go to System UI > UI Actions.

    2. Click on New to create a new UI action.

    3. Define the UI Action:

    Name: Enter a name, e.g., “Send Reminder”.

    Table: Select the table that represents the current case (e.g., sn_customerservice_case).

    Condition: Set any conditions if needed, e.g., current.state != 'Closed' to avoid sending reminders for closed cases.

    Form Button: Set this to true to add the button to the form.

    Action name: This will be used in your client-side script, e.g., “sendReminder”.

     

    Step 2: Add Client Script to Trigger Server Script

     

    In the UI Action, add the following in the Client field:

     

    function() {

        var ga = new GlideAjax('SendReminderScript'); // Calls a script include

        ga.addParam('sys_id', g_form.getUniqueValue()); // Get the case ID

        ga.getXMLAnswer(function(response) {

            var result = response.responseXML.documentElement.getAttribute("answer");

            if (result === "success") {

                g_form.addInfoMessage("Reminder

CharanjeetSingh
Tera Contributor

Hi @Awantika verma ,

The logic to fetch the last email sent to you can glide on 'sys_email' table and in query pass the email of the person and order descending by update date with limit 1.

This will give you the last email. Now if record is greater than 0 then you can trigger the notification.

 

Please like if you find it helpful.

Connect: https://www.linkedin.com/in/charanjeet-singh-virdi-9739bb140

Hi Charanjeet ,
Could you help me with the script and also 
I need to develop a UI action button in CSM workspace which will send reminder when pressed   to last email sent to person. Need help in step by step in configuring action button in CSM workspace and the script which will extract the last email sent to person and then send reminder notification to the current case.

Step 1: Create the UI Action for the Reminder Button

 

1.Go to UI Actions : Navigate to `System UI > UI Actions` in ServiceNow.

2. Create New UI Action:

   - Table: Set to the relevant case table, such as `sn_customerservice_case`.

   - Name: Give it a name, like "Send Reminder."

   - Action name: This is an internal name, e.g., `send_reminder`.

   - Form Button: Check this box to show it as a button.

   - CSM Workspace Form: Ensure it’s set to show in the workspace form.

   - Condition: Set a condition if needed, e.g., `current.state == "Open"`.

   - Script: Add the script

 

3. Save and Activate the UI action.

 

Step 2: Write the Script in the UI Action

The script should find the last sent email for the contact, extract the required details, and trigger a reminder notification.

// Fetch the last email sent to the contact

var emailLogGR = new GlideRecord('sys_email');

emailLogGR.addQuery('recipient', current.contact.email); // Assume 'contact.email' holds recipient’s email

emailLogGR.addQuery('type', 'send'); // Filters only sent emails

emailLogGR.orderByDesc('sys_created_on'); // Orders to get the latest email first

emailLogGR.query();

 

if (emailLogGR.next()) {

    // Send reminder notification

    var emailVars = {}; // Add any additional variables you want to send in the email

    emailVars.subject = "Reminder: " + emailLogGR.subject;

 

    // Send notification to the contact for the current case

    gs.eventQueue("send.reminder.notification", current, emailLogGR.sys_id, emailVars.subject);

    gs.addInfoMessage("Reminder sent to " + current.contact.email);

} else {

    gs.addInfoMessage("No previous email found for this contact.");

}

 

 Step 3: Configure the Notification for the Reminder

 

1. Create Notification: Go to `System Notification > Email > Notifications`.

2. New Notification:

   - Name: e.g., "Case Reminder Notification".

   - Table: `sn_customerservice_case`.

   - When to send: Check `Event is fired` and select the event you defined earlier, e.g., `send.reminder.notification`.

   - Who will receive: Use the case’s contact field, or specify the recipient.

   - Message Content: Use `${event.parm1}` to include the email subject in the message, or add more fields if needed.

3. Save the notification.

 

 

Please like if you find it helpful.

 

Connect: https://www.linkedin.com/in/charanjeet-singh-virdi-9739bb140