Query on Email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:32 AM - edited 01-26-2023 07:21 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:39 AM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:41 AM
@Hemant Goldar can we use without using two glideRecords?
can we show Different tables from Task glideRecord itself?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:47 AM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:54 AM - edited 01-26-2023 06:55 AM
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.