- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:30 PM
Hi All,
I have written an email script that displays the variables of a catalog with values in the notification for the sc_request table. However there's an issue when submitting an order guide , in this case when the notificationis triggered from the sc_request table the variables are repeated .
for example: if three catalog items are attached in the order guide the variables from all three catalog items are shown in the notification.
i want to restrict this so that only the variables from one catalog item with values are displayed.
Can anyone please help me on this.
Please find blow attached code:
(function runMailScript(current, template, email, email_action, event) {
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", current.sys_id);
ritm.query();
while(ritm.next()) {
//template.print('<b>Detalle del Elemento Pedido:</b><br/><br/>');
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery("request_item", ritm.sys_id);
varown.addQuery("sc_item_option.value != ''null'' ");
varown.orderBy("sc_item_option.order");
varown.query();
template.print('<table cellspacing="5" cellpadding="5" width="100%" style="border-color:#000000; height:30px; border-collapse:collapse;">');
template.print('<tr><th style="width: 35%; border:1px solid black;" align="left">Variable</th><th style="border:1px solid black;" align="left">Answer</th></tr>');
while (varown.next()){
var visible = varown.sc_item_option.item_option_new.visible_summary;
var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && question.getLabel() != "null" && question.getDisplayValue() != "undefined"){
template.print('<tr><td style="border:1px solid black;">' + question.getLabel() + '</td><td style="border:1px solid black;"><strong>' + question.getDisplayValue() + '</strong></td></tr>');
}
}
template.print('</table>');
}
})(current, template, email, email_action, event);
THanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:51 PM
Hi @Mani60
You need to modify your script as bellow:
Replace "while(ritm.next())" with "if (ritm.next())" This line ensures only the first catalog item is processed.
The while (ritm.next()) has been replaced to restrict the script to process just one item.
i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:51 PM
Hi @Mani60
You need to modify your script as bellow:
Replace "while(ritm.next())" with "if (ritm.next())" This line ensures only the first catalog item is processed.
The while (ritm.next()) has been replaced to restrict the script to process just one item.
i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:03 PM
@Rajesh Chopade1 Thank you its working as expected.