Email script returns a static value in notification that is different from the value in the request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2024 02:21 PM - edited 10-14-2024 04:47 AM
Hello!
I have a notification that I want to trigger when a request from a specific order guide is set to Closed Complete.
In this notification I want to return some values about the request, such as Server OS if it's a server. The problem is that it returns a static value all the time that doesn't reflect what was chosen in the request. I just don't understand why.
Here is what was actually chosen from a table called "u_technical_services_lookup" in my request:
Instead I always get "Ubuntu Server 18.04 LTS (Kontorstid)" like shown in the notification below:
This very value, "Ubuntu Server 18.04 LTS (Kontorstid)", also comes up in the system logs. "Ubuntu Server 18.04 LTS (Kontorstid)" comes from here in the same "u_technical_services_lookup" table:
Here is how the script looks:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) { (function() { var request = current.request; // Hämta sc_request var osVersion = ''; // Hämta alla sc_req_item under sc_request var reqItemGR = new GlideRecord('sc_req_item'); reqItemGR.addQuery('request', request.sys_id); reqItemGR.query(); while (reqItemGR.next()) { // Logga sc_req_item ID gs.log('Req Item ID: ' + reqItemGR.sys_id); // Hämta värde från u_technical_services_lookup baserat på u_category var techServiceGR = new GlideRecord('u_technical_services_lookup'); techServiceGR.addQuery('u_category', 'STARTSWITH', 'server_os'); techServiceGR.addQuery('sc_req_item', reqItemGR.sys_id); // Kontrollera att sc_req_item är kopplad techServiceGR.query(); if (techServiceGR.next()) { // Logga teknisk tjänst ID och OS-version gs.log('Tech Service ID: ' + techServiceGR.sys_id); gs.log('OS Version: ' + techServiceGR.u_name); osVersion = techServiceGR.u_name; // Hämta värdet namn break; // Avsluta loopen när vi har hittat en matchning } } // Logga den slutliga OS-versionen gs.log('Final OS Version: ' + osVersion); // Använd template.print för att inkludera OS-versionen i email scriptet template.print('OS Version: ' + osVersion); })(); })(current, template, email, email_action, event);
In this example, you can see that the Technical Services Lookup table becomes a variable under a Request Item:
KEEP IN MIND that this Request (sc_request) creates several Request Items (sc_req_item) under and it comes not from a form, but a series of Rule bases.
Also, there are plentiful of records regarding OS versions in the "u_technical_services_lookup" table with Category starting with "server_os".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 04:49 AM
The Lookup table is used as a variable somehow, as you can se under one of the request items under the request (parent):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 04:55 AM
That's good. Just replace 'variable_name' with the name of the Server OS variable, and you should see the correct lookup record Name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 05:16 AM
i replaced it with u_name, but now the notification says undefined. Do you think I need some kind of glideRecord for the Lookup table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 05:19 AM
What does your script look like now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 05:33 AM
It looks like this:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
(function() {
var request = current.request; // Hämta sc_request
var osVersion = '';
// Hämta alla sc_req_item under sc_request
var reqItemGR = new GlideRecord('sc_req_item');
reqItemGR.addQuery('request', request);
reqItemGR.query();
while (reqItemGR.next()) {
// Logga sc_req_item ID
gs.log('Req Item ID: ' + reqItemGR.sys_id);
osVersion = reqItemGR.variables.u_name; // Hämta värdet namn
break; // Avsluta loopen när vi har hittat en matchning
}
// Logga den slutliga OS-versionen
gs.log('Final OS Version: ' + osVersion);
// Använd template.print för att inkludera OS-versionen i email scriptet
template.print('OS Version: ' + osVersion);
})();
})(current, template, email, email_action, event);