- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 07:41 PM
Hi everyone!
I want to compare the field 'version' and 'latest_version' and if they dont match print the value of the name field of the 'sys_store_app' table, I have the following script but it just prints the whole table
Can someone help me, please 🙂
(function runMailScript(template, current, email, email_action, event) {
var tb = new GlideRecord ('sys_store_app');
tb.query();
try{
while (tb.next()){
tb.addQuery('version', 'latest_version');
tb.version == tb.latest_version;
template.print('Name1: ' + tb.name + '\n');
}
}catch(ex){
gs.info(ex);
}
})(template, current, email, email_action, event);
Solved! Go to Solution.
- Labels:
-
Agent Workspace
-
Event Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 07:56 PM
Hi, unfortunately your requirement\intention is not clear from your script.
You are running the script as a notification email script - you are populating into an email body?
Currently you query all records on sys_store_app and are querying the version filed for a string value 'latest_version'.
I am guessing you want to query 'sys_store_app' and return all records into the email body where the 'version' is not the same as 'latest_version' ?
Perhaps try something like this
(function runMailScript(template, current, email, email_action, event) {
var tb = new GlideRecord('sys_store_app');
tb.query();
while (tb.next()) {
// check each record as you loop through them looking for mismatches and print to the email body if you find one
if (tb.version != tb.latest_version) {
template.print('Name1: ' + tb.name + '\n');
}
}
})(template, current, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 07:56 PM
Hi, unfortunately your requirement\intention is not clear from your script.
You are running the script as a notification email script - you are populating into an email body?
Currently you query all records on sys_store_app and are querying the version filed for a string value 'latest_version'.
I am guessing you want to query 'sys_store_app' and return all records into the email body where the 'version' is not the same as 'latest_version' ?
Perhaps try something like this
(function runMailScript(template, current, email, email_action, event) {
var tb = new GlideRecord('sys_store_app');
tb.query();
while (tb.next()) {
// check each record as you loop through them looking for mismatches and print to the email body if you find one
if (tb.version != tb.latest_version) {
template.print('Name1: ' + tb.name + '\n');
}
}
})(template, current, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 08:09 PM
Thanks! It worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 08:17 PM
In this case the code can be made a bit more optimized by selecting only those records that fulfill the if condition:
(function runMailScript (template, current, email, email_action, event) {
var tb = new GlideRecord('sys_store_app');
tb.addEncodedQuery('versionNSAMEASlatest_version');
tb.query();
while (tb.next()) {
// No check needed, the version will be different from latest version
// by defintion for all retrieved records
template.print('Name1: ' + tb.name + '\n');
}
})(template, current, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 06:46 AM
Thanks the support members for sharing the script. As I was also facing the issue in the comparison names at adope lightroom. But after reading their replies and the script that share worked for me. when I applied the script got the desired results for which I was looking.