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

Hi Charanjeet,

I used the above code in UI action script part, but I was not able to refer to the current case.And event was not also triggering

Awantika verma
Tera Contributor

When I am configured UI action button it is appearing in the case view but not in the workspace ,I have checked the workspace option instead

CharanjeetSingh
Tera Contributor

@Awantika verma 

Could you please upload the screenshot of the UI Action configurations.

For further requirements let me check.

Yuvraj Sharma
Tera Expert

YuvrajSharma_0-1729863836896.png


Make sure to enable the other checkbox as well : "Format for Configurable Workspace". Please refer the screenshot

 

kumar2sdes
Tera Contributor

 

UI action button in CSM Workspace that sends a reminder email for the last email sent to a person, you need to configure the following:

Step 1: Create the UI Action

  1. Navigate to System UI > UI Actions in the ServiceNow instance.

  2. Click New to create a new UI action.

  3. Fill out the following fields:

    • Name: Send Reminder
    • Table: Case (or the table for CSM Workspace)
    • Action name: send_reminder
    • Show insert: True (if you want the button to be visible on new records).
    • Show update: True (if you want the button visible on existing records).
    • Condition: Write a condition that ensures the button only appears when appropriate. For example:
       
      current.state != 'Closed';
    • Script: Leave blank for now; you will implement this in Step 4.
  4. Save the UI action.

Step 2: Add the Button to CSM Workspace

  1. Navigate to Workspace Experience > Workspace Actions.
  2. Create a new action:
    • Name: Send Reminder
    • Table: Case (or the appropriate table).
    • Action Type: UI Action
    • Action Name: send_reminder.
  3. Add this action to the appropriate workspace view under Workspace Experience > View Configurations.

Step 3: Identify the Last Sent Email

The last email sent can be retrieved from the sys_email table. Use the following logic:

  1. Query the sys_email table to find the most recent email (type=send) linked to the case's associated person.
  2. Use the recipient email or user reference to filter the relevant email.

Step 4: Write the UI Action Script

Here is the script for the UI action to send the reminder:

Code sample

(function executeAction() { // Ensure the case has a contact if (!current.u_contact || !current.u_contact.email) { gs.addErrorMessage("No contact email found for this case."); return; } var contactEmail = current.u_contact.email; var caseSysId = current.sys_id; // Query sys_email for the last sent email linked to the person var emailGR = new GlideRecord('sys_email'); emailGR.addQuery('recipient', contactEmail); // Target the email address of the contact emailGR.addQuery('type', 'send'); // Only sent emails emailGR.orderByDesc('sys_created_on'); // Most recent first emailGR.setLimit(1); // Fetch only the latest email emailGR.query(); if (emailGR.next()) { // Found the last email var lastSubject = emailGR.subject; var lastBody = emailGR.body; // Send reminder notification var email = new GlideEmailOutbound(); email.setFrom(gs.getProperty('glide.email.user')); // Default system email email.setTo(contactEmail); email.setSubject("Reminder: " + lastSubject); email.setBody("This is a reminder regarding the previous email:\n\n" + lastBody); if (email.send()) { gs.addInfoMessage("Reminder email sent successfully."); } else { gs.addErrorMessage("Failed to send the reminder email."); } } else { gs.addErrorMessage("No previous email found for the contact."); } })();

Step 5: Test the Button

  1. Open a case in the CSM Workspace.
  2. Ensure the contact has an email address.
  3. Click the Send Reminder button.
  4. Verify that:
    • The last email is retrieved.
    • A reminder notification is sent successfully.
    • Relevant success or error messages are displayed.

Step 6: Optional - Add Notification Template

To standardise the reminder content, you can create a Notification:

  1. Navigate to System Notification > Email > Notifications.
  2. Create a notification template for the reminder email.
  3. Use the GlideRecord script above to trigger this notification.

This approach ensures modularity and better manageability for email content.