Issue with email client template

Aruna13
Tera Contributor

Hi,

 

I have a custom table and a corresponding client template. The issue is the client template is not working for "Reply to" field. I have a written script include for the same and seems to be issue with it. The script include should display the email address if the category is shipping, but it is not. It always displays other categories email address. Since i am not that much familiar with the coding, can you please help me this?

 So this is the requirement, the "Reply To" field should automatically populate the email address based on the category field(which is custom field) of the record where the email client template is running on.

 

Below is the script include:

var AR_EmailClient = Class.create();
AR_EmailClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getreplyTo : function(){
    var email = new GlideRecord('u_sr_shared_ar') //this is the custom table
    var y = '';
    if(email.u_category == 'Shipping'){
        y = gs.getProperty('AR_requestFromTo_Shipping');
    }else{
        y = gs.getProperty('AR_request_FromTo_other_categories');
    }
    return y;
},
   
    type: 'AR_EmailClient'
});
 
In client template:
Reply To :    javascript: new AR_EmailClient().getreplyTo();
 
 
Thanks in advance!!
1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@Aruna13 

It seems like the issue lies in how you're accessing the values from the GlideRecord object. When you instantiate a GlideRecord, you need to first query for a specific record or loop through a set of records to access their values. In your script include, you're missing the query to fetch the correct record based on the current context.

 

 

var AR_EmailClient = Class.create();
AR_EmailClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getreplyTo: function() {
        // Retrieve the current record from the client script's context
        var gr = new GlideRecord('u_sr_shared_ar'); // Custom table name
        // Add a condition to retrieve the specific record based on the current record ID
        if (gr.get(current.sys_id)) { // Assuming 'current' is accessible in the client script
            // Access the category field value of the current record
            var category = gr.u_category.toString().trim();
            var replyTo = '';
            // Check the category value to determine the reply-to email address
            if (category === 'Shipping') {
                replyTo = gs.getProperty('AR_requestFromTo_Shipping');
            } else {
                replyTo = gs.getProperty('AR_request_FromTo_other_categories');
            }
            return replyTo;
        } else {
            gs.error('Record not found or access denied');
            return ''; // Return empty string if record not found or access denied
        }
    },

    type: 'AR_EmailClient'
});

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

3 REPLIES 3

Maddysunil
Kilo Sage

@Aruna13 

It seems like the issue lies in how you're accessing the values from the GlideRecord object. When you instantiate a GlideRecord, you need to first query for a specific record or loop through a set of records to access their values. In your script include, you're missing the query to fetch the correct record based on the current context.

 

 

var AR_EmailClient = Class.create();
AR_EmailClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getreplyTo: function() {
        // Retrieve the current record from the client script's context
        var gr = new GlideRecord('u_sr_shared_ar'); // Custom table name
        // Add a condition to retrieve the specific record based on the current record ID
        if (gr.get(current.sys_id)) { // Assuming 'current' is accessible in the client script
            // Access the category field value of the current record
            var category = gr.u_category.toString().trim();
            var replyTo = '';
            // Check the category value to determine the reply-to email address
            if (category === 'Shipping') {
                replyTo = gs.getProperty('AR_requestFromTo_Shipping');
            } else {
                replyTo = gs.getProperty('AR_request_FromTo_other_categories');
            }
            return replyTo;
        } else {
            gs.error('Record not found or access denied');
            return ''; // Return empty string if record not found or access denied
        }
    },

    type: 'AR_EmailClient'
});

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Aruna13
Tera Contributor

Hi,

 

Thank you!! it worked out for Email client template, but it is now not working for "Reply, Reply All and Forward" email client templates in activity log. Instead of showing the correct values, it is displaying the other incorrect email address. I am using same "Reply To" condition here in these client templates. How should i correct it now? Any suggestions please!!

 

Thanks in Advance!!

 

@Aruna13 

I think you to ensure that in the context of these email client templates, the current variable is still accessible and accurately represents the record you're interested in. Sometimes, in different contexts, the current variable may not be available, or it might represent a different record.

Also Verify that the necessary data fields (such as u_category) are available and populated correctly on the record when these email client templates are triggered. It's possible that the data required for determining the reply-to email address may not be available or might be different in these contexts.

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks