Help Needed with Email Script

SandeepKSingh
Kilo Sage

I have a custome table (u_wells_fargo_bank_india). I need a link in my notification triggered , If I click on the link, It wil redriect me to that Table with the count

2 ACCEPTED SOLUTIONS

Ravi Gaurav
Giga Sage
Giga Sage

Its pretty Straight:-

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {




    var query='u_account_type=current';
    var x = new GlideRecord('u_wells_fargo_bank_india');
    x.addEncodedQuery(query);
    x.query();
    if (x.next()) {
           var count=x.getRowCount(); //5

 var str="count of Record : "+"<a href=\"https://"+gs.getProperty('instanceName')+".service-now.com/u_wells_fargo_bank_india_list.do?sysparm_query="+query+"\">"+"The Count is "+count+"</a>";

 
 template.print(str);
    }


})(current, template, email, email_action, event);
 
--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

Ravi Gaurav
Giga Sage
Giga Sage

can you also try with glide aggerate for only count :-


var ga = new GlideAggregate('u_wells_fargo_bank_india');
ga.addAggregate('COUNT');
ga.query();
var count = 0;
if (ga.next()) {
count = ga.getAggregate('COUNT');
}
gs.info('Record count for u_wells_fargo_bank_india: ' + count);
})(current, previous);

 

This just for count but earlier script will work as per all valid scenario

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

2 REPLIES 2

Ravi Gaurav
Giga Sage
Giga Sage

Its pretty Straight:-

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {




    var query='u_account_type=current';
    var x = new GlideRecord('u_wells_fargo_bank_india');
    x.addEncodedQuery(query);
    x.query();
    if (x.next()) {
           var count=x.getRowCount(); //5

 var str="count of Record : "+"<a href=\"https://"+gs.getProperty('instanceName')+".service-now.com/u_wells_fargo_bank_india_list.do?sysparm_query="+query+"\">"+"The Count is "+count+"</a>";

 
 template.print(str);
    }


})(current, template, email, email_action, event);
 
--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Ravi Gaurav
Giga Sage
Giga Sage

can you also try with glide aggerate for only count :-


var ga = new GlideAggregate('u_wells_fargo_bank_india');
ga.addAggregate('COUNT');
ga.query();
var count = 0;
if (ga.next()) {
count = ga.getAggregate('COUNT');
}
gs.info('Record count for u_wells_fargo_bank_india: ' + count);
})(current, previous);

 

This just for count but earlier script will work as per all valid scenario

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/