I need to get a value from a related list variable in email notifications

Onoderav
Tera Contributor

Hello! I'm kind of new to servicenow platform and I need some help, please.
I've defined the table "asmt_assessment_instance" to my email notification and I do a lot of work using its variables, but now, I need to get the value of a column that appears in a related list on a record from the "asmt_assessment_instance" table. I don't know if I expressed myself correctly.. ask me more and I'll try to make it clear.

As below, the field value I wanted to get is from those three records from column named Value.

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Onoderav 

 

Greetings!!

 

Where you want to show this Value and what information this Value contain?

 

Please mark my answer helpful or solution accepted if it serves the purpose.

Regards

Atul G

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Karthiga S
Kilo Sage

Hi @Onoderav,

 

You can use the below Notification Email script to get the Values of the respective instance and Values in the Email.

  var as= new GlideRecord('asmt_assessment_instance_question');
   as.addQuery('instance',current.instance.sys_id);
as.addQuery('metric', 'Sys_id of the Question'); // QUESTION SysID if you want Specific Question's Value. Remove if its not applicable
   as.query();
   while (as.next()) {
        template.print(as.string_value); // Add Value instead of String Value	
    }

Note : Read the comments in the code carefully and adjust as required.

 

Please mark my answer Correct and Hit Like if this Works!

 

Regards,

Karthiga

AparnaSahu
Tera Guru

reate mail scripts in System Policy > Email > Notification Email Script->

(function runMailScript(current, template, email, email_action, event) {

 

  var item = new GlideRecord("table_name");

 

  item.addQuery("request", current.sys_id);

 

  item.query();

 

  while(item.next()) {

 

  var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();

 

  var misc = item.variable_pool.alt_poc;

 

  template.print(catalogItem + "<br/> Field: " + misc);

 

  }

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

 

Now you can call the above mail script in email notification as ${mail_script:script name}