Query on Email script

instance
Tera Contributor

I have Created Email script that displays like this table method

i need the Change_request and Incident Records to be Displayed Separately.

in Separate table .

 

email Script:

 

var tas = new GlideRecord("task");
tas.addQuery('assigned_to',current.sys_id);
tas.query();
if (tas.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>InActive Users in Task :</strong></font></td></tr></tbody></table>');
var tb2 = '<table style="height: 293px;" width="100%"><tbody>';

var tab2 = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +

'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned To</b>' + '</td>' +


'</tr>';
template.print(tab2);
}

while (tas.next()) {

var clsed2 = '<tr>' +
'<td>' + tas.number + '</td>' +
'<td>' + tas.assigned_to.name + '</td>'
'</tr>';
template.print(clsed2);

 

what changes needs to be done?
}

var tab_end2 = '</tbody> </table>';
template.print(tab_end2);

8 REPLIES 8

Hemant Goldar
Mega Sage
Mega Sage

Hi @instance  ,

 

Please use the below email script

email Script:

 

var tas = new GlideRecord("incident");
tas.addQuery('assigned_to',current.sys_id);
tas.query();
if (tas.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>InActive Users in Task :</strong></font></td></tr></tbody></table>');
var tb2 = '<table style="height: 293px;" width="100%"><tbody>';


var tab2 = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +

'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned To</b>' + '</td>' +


'</tr>';
template.print(tab2);
}

while (tas.next()) {

var clsed2 = '<tr>' +
'<td>' + tas.number + '</td>' +
'<td>' + tas.assigned_to.name + '</td>'
'</tr>';
template.print(clsed2);

 



var tab_end2 = '</tbody> </table>';
template.print(tab_end2);




var tas1 = new GlideRecord("change_request");
tas1.addQuery('assigned_to',current.sys_id);
tas1.query();
if (tas1.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>InActive Users in Task :</strong></font></td></tr></tbody></table>');
var tb22 = '<table style="height: 293px;" width="100%"><tbody>';


var tab22 = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +

'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned To</b>' + '</td>' +


'</tr>';
template.print(tab22);
}

while (tas1.next()) {

var clsed22 = '<tr>' +
'<td>' + tas1.number + '</td>' +
'<td>' + tas1.assigned_to.name + '</td>'
'</tr>';
template.print(clsed22);

 


var tab_end22 = '</tbody> </table>';
template.print(tab_end22);


 

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

@Hemant Goldar can we use without using two glideRecords?

can  we show Different tables from Task glideRecord itself?

Yes we can make use of  sys_class_name field.

sys_class_name= incident OR change_request

Use below code 

email Script:

 

var tas = new GlideRecord("task");
tas.addEncodedQuery()('sys_class_name=change_request^ORsys_class_name=incident^assigned_to='current.sys_id);
tas.query();
if (tas.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>InActive Users in Task :</strong></font></td></tr></tbody></table>');
var tb2 = '<table style="height: 293px;" width="100%"><tbody>';


var tab2 = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +

'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned To</b>' + '</td>' +


'</tr>';
template.print(tab2);
}

while (tas.next()) {

var clsed2 = '<tr>' +
'<td>' + tas.number + '</td>' +
'<td>' + tas.assigned_to.name + '</td>'
'</tr>';
template.print(clsed2);

 


}

var tab_end2 = '</tbody> </table>';
template.print(tab_end2);

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

Dubz
Mega Sage

As an alternative to Hemants solution, you could use tas.orderBy('sys_class_name') to order the results of the glide query by their class, then they'll all print out grouped together rather than all mixed up.