Field value from RITM table is not shown in notification via email script

martyna3
Tera Contributor

We have trouble with the Email Script:

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var util = new global.test();
    var activeAccess = util.getCurrentAccess(current.getUniqueValue());
	var hasAdditional = false;
    if (activeAccess.length > 0) {
        var tableData = [];
        var query = [];
        for (var i in activeAccess) {
            query.push('sys_id=' + activeAccess[i].record_id);
        }
        var gr = new GlideRecord('u_xyz');
        gr.addEncodedQuery(query.join('^OR'));
        gr.query();
        while (gr.next()) {
			
			
			if (gr.getDisplayValue('u_access_to') === 'Additional system (enter manually)')
				{
					hasAdditional = true;
					var reqGr = new GlideRecord('sc_req_item');
					if (reqGr.getDisplayValue('number')  === 'RITM9349074')
						{
							template.print('("Additional system")');
						}
					else 
						{
							template.print('(No "Additional system")');
						}
				}
				template.print('- ' + gr.getDisplayValue('u_access_to') + ' — ' + gr.getDisplayValue('u_ritm_number') + '<br>');
        }
    } else {
		template.print('(No requests in Request Archive)');
	}


})(current, template, email, email_action, event);

 

When we execute this condition, only "else" is executed. The field in sc_req_item is called 'number' and we have a record there with the value of RITM9349074.
We tried to use reqGr.getValue, reqGr.getDisplayName, sys_id, it did not show any value.
It seems that retrieving information from the second table does not work.
We would like to combine two tables because we need one piece of information from the u_xyz table if we want to check different information from the second table sc_req_item. In notifications based on the user table, an email should be a visible value from the field "details" which is shown in the RITM record.

 

 

if (reqGr.getDisplayValue('number')  === 'RITM9349074')
						{
							template.print('("Additional system")');
						}
					else 
						{
							template.print('(No "Additional system")');
						}

 

 

1 ACCEPTED SOLUTION

Harsh_Deep
Giga Sage
Giga Sage

Hello @martyna3 

 

Please use this -

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var activeAccess = new global.test().getCurrentAccess(current.getValue('sys_id'));
	var hasAdditional = false;
    if (activeAccess.length > 0) {
        var tableData = [];
        var query = [];
        for (var i in activeAccess) {
            query.push('sys_id=' + activeAccess[i].record_id);
        }
        var gr = new GlideRecord('u_xyz');
        gr.addEncodedQuery(query.join('^OR'));
        gr.query();
        while (gr.next()) {
			
			
			if (gr.u_access_to.getDisplayValue() === 'Additional system (enter manually)')
				{
					hasAdditional = true;
					var reqGr = new GlideRecord('sc_req_item');
                                        reqGr.addQuery('number','RITM9349074');
                                        reqGr.query();
					if (reqGr.next())
						{
							template.print('("Additional system")');
						}
					else 
						{
							template.print('(No "Additional system")');
						}
				}
				template.print('- ' + gr.u_access_to.getDisplayValue() + ' — ' + gr.u_ritm_number.getDisplayValue() + '<br>');
        }
    } else {
		template.print('(No requests in Request Archive)');
	}


})(current, template, email, email_action, event);

 

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

View solution in original post

5 REPLIES 5

Its okay @Muhammad Hamza  

 

But I have posted before 11 minutes when you posted. But the same answer will make confusion to the readers.

 

Thanks
Harsh