Open Outlook Client using Declarative Actions

Meet Mewada
Tera Expert

Hi Team,

 

My use case is to open an outlook email upon clicking a button on a workspace form. I thought to use a declarative action implemented as a server script which includes below line:

action.setRedirectURL("mailto:recipient@example.com")
 
I also tried, gs.setRedirect("mailto:recipient@example.com") & gs.setRedirectURL("mailto:recipient@example.com")
 
However, this doesn't work. Any suggestions to achieve this use case?
 
Thanks in advance.
 
Regards,
Meet M
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Meet Mewada 

you need to use client side UI action and write code in workspace client script for this.

Something like this

 

function onClick(g_form) {

    var email = 'recipient@example.com';
    var subject = 'Subject of the email';
    var body = 'This is the email body.';

    // Construct the mailto link
    var mailtoLink = 'mailto:' + email + '?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body);

    // Open the email client
    open(mailtoLink);
}

 

AnkurBawiskar_1-1751872623593.png

 

Output: when I clicked it opened this

AnkurBawiskar_0-1751872601421.png

 

 

Then I selected Outlook app and it opened the email form

AnkurBawiskar_0-1751872816982.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Martin Virag
Tera Guru

Why would you like to use a Declarative action for this? It works with a simple client side UI action (or client side declarative action)

Just use the following example script (I tried with window.location however it always returned undefined in the console which shouldn't have happened):

function executeAction() {
  var subject = "Test Subject";
  var body = "Hello from ServiceNow UI Action!";

  var mailto_link = "mailto:someone@example.com?subject="
                  + encodeURIComponent(subject)
                  + "&body="
                  + encodeURIComponent(body);

  top.location.href = mailto_link;
}

 

Meet Mewada
Tera Expert

Thank you all! Much appreciated.