How to Include Fields from Other Tables in Notifications

TStark
Kilo Sage

I have a notification on the Demand table. How can I include the value of a field from the Requirement [dmn_requirement] table? Dot walking doesn't work as the two tables aren't directly related.

Thanks,
AJ

1 ACCEPTED SOLUTION

@TStark , try the below code

 

(function runMailScript(current, template, email, email_action, event) {
var demand = new GlideRecord("dmn_requirement");
demand.addQuery("demand", current.sys_id)
demand.query() //if its for one record
if(demand.next()){
template.print('Demand Requirement' + demand.short_description.getDisplayValue());
}
})(current, template, email, email_action, event);

Please Mark my answer Helpful & Accepted if I have answered your question.

Thanks,

Alka

 

View solution in original post

7 REPLIES 7

So looks like you Already have the mail script. You can just add some label to it as below

template.print('DMN Requirement: '+short_description.getDisplayValue());


Please mark this response as correct or helpful if it assisted you with your question.

@TStark , try the below code

 

(function runMailScript(current, template, email, email_action, event) {
var demand = new GlideRecord("dmn_requirement");
demand.addQuery("demand", current.sys_id)
demand.query() //if its for one record
if(demand.next()){
template.print('Demand Requirement' + demand.short_description.getDisplayValue());
}
})(current, template, email, email_action, event);

Please Mark my answer Helpful & Accepted if I have answered your question.

Thanks,

Alka

 

You forgot the GR variable infront.
short_description.getDisplayValue() doesn't work, because it's not point to anything. 

Also if it's only one record, do not forget the set limit

 

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

var grDemand = new GlideRecord("dmn_requirement");
grDemand.addQuery("demand", current.getUniqueValue())
grDemand.setLimit(1);
grDemand.query() //if its for one record

if(grDemand.next()){
template.print(grDemand.short_description);
}
})(current, template, email, email_action, event);

 

OR (even shorter)

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

var grDemand = new GlideRecord("dmn_requirement");
if(grDemand.get("demand", current.getUniqueValue())) {
template.print(grDemand.short_description);
}

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


Hope that helps