- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:14 AM - edited 02-05-2025 07:15 AM
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:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 07:10 AM
Are the email client template and the script include in the same scope? The script include is not accessible form all application scopes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 07:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 05:58 PM
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)
- Extracts the user field from the sourceEmail record
- Checks if that user exists in sys_user
- If the user exists, returns "user_id"
- 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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:14 PM
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'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 09:31 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 09:37 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader