- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 04:55 AM
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")');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:23 AM
Hey @martyna3,
You need to get the specific record of the sc_req_item table.
What you are doing is that you are just initializing the GlideRecord for the Requested Item table, and not querying the specific record.
What you can do is:
var reqGr = new GlideRecord('sc_req_item');
// here get the number from the GR of 'u_xyz'
// you need to query the data first
// Step 1
reqGr.addEncodedQuery('number='+<PASS_THE_NUMBER_HERE>);
reqGr.query();
reqGr.next();
// Or Step 2, if you have sys_id
reqGr.get(<RECORD_SYS_ID>);
if (reqGr.getDisplayValue('number') === 'RITM9349074')
{
template.print('("Additional system")');
}
else
{
template.print('(No "Additional system")');
}
Hope it helps.
Kindly appreciate the efforts of community contributors by marking appropriate response as the correct solution and helpful, this may help other community users to follow the right solution in the future.
Thanks,
Hamza
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:28 AM
Hello @Muhammad Hamza
Same thing I also posted then it's not necessary to post the same answer again. Before posting any answer please try to read whole thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:33 AM
Hey @Harsh_Deep,
I read the whole thread first. When I came to this question, I didn't see your answer. I reloaded the page again. There was no answer from you. Therefore, I started writing my answer and I posted it.
I don't go and post answers to questions if they are already answered.
Regards,
Hamza