How to call a decision table from email client template recipients To field

mfhaciahmetoglu
Mega Sage

Hello,

 

Based on the "taxi company" field's choice list value, I want to return a different email address on Email Client Script > Recipients > To field.

 

Any ideas how can this be done?

 

One note related to this.

 

I have already created a script include to call from To field.

 

Script include:

 

// Script Include (Client Callable)
var UserEmailUtil = Class.create();
UserEmailUtil.prototype = {
    initialize: function() {
    },

    getEmailAddress: function() {
        gs.info("is this working?");
        return "test@example.com";
    },

    type: 'UserEmailUtil'
};
 
To field:
mfhaciahmetoglu_0-1738768415033.png

 

For some reason this does not work. I see that gs.info is not displayed either. 

 

Any ideas why? (my app is a custom app, so the scope is not global).

 

Best,

Firat

 

 

2 ACCEPTED SOLUTIONS

Are the email client template and the script include in the same scope? The script include is not accessible form all application scopes.

View solution in original post

Hi @Sheldon  Swift ,

 

I made the script include accessible from all scopes and then used the scope API before calling, then it worked fine.

 

But it is still a mystery why it does not work when it is accessible only from the scope application 😕

 

Best,

Firat

View solution in original post

18 REPLIES 18

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @mfhaciahmetoglu - I don't think your script include should be client callable. Take a look at the following example:

var EmailClientTemplateEvaluator = Class.create();
EmailClientTemplateEvaluator.prototype = {
    initialize: function() {
    },
	getRecipientsForReplyEmails: function(sourceEmail) {
		var user = sourceEmail.getValue("user");
		var gr = new GlideRecord("sys_user");
		return user && gr.get(user) ? "user_id" : "user";
	},
    type: 'EmailClientTemplateEvaluator'
};

 

Usage: javascript: new EmailClientTemplateEvaluator().getRecipientsForReplyEmails(current)

 

  1. Extracts the user field from the sourceEmail record
  2. Checks if that user exists in sys_user
  3. If the user exists, returns "user_id"
  4. If the user does not exist, record does not exist, "user" otherwise

In the example, the getRecipientsForReplyEmails method returns a field name, but you can provide an email address (or a comma-separated list of email addresses).

Ankur Bawiskar
Tera Patron
Tera Patron

@mfhaciahmetoglu 

your script include should be client callable and should not have initialize function

var UserEmailUtil = Class.create();
UserEmailUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getEmailAddress: function() {
        gs.info("is this working?");
        return "test@example.com";
    },

    type: 'UserEmailUtil'
});

AnkurBawiskar_0-1738811664087.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

Hi @Ankur Bawiskar - The script executes server-side, not client-side, so I’m not seeing why the Script Include should be client callable. Could you clarify your reasoning?

@Sheldon  Swift 

Because it doesn't work when script include is not client callable. I tested that.

I believe the reason is the UI page "email_client" is getting called and it requires script include to be client callable to invoke it.

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