Email notifications - how to get chosen Select Box question Price variable?

jimmy jensen
Kilo Contributor

[CHALLENGE]

I have a catalog item with a select box containing multiple items to choose from, that has a price variable assigned, and I need to template.print() that price in an email notification or an email notification script.

[QUESTION]

How do I go about doing that? I spend most of a day trying to figure it out (dot walk, current.variables, glide records) but I have not been successful, other then getting the total price of all selected question topics on the catalog item by using ${current.price}.

[VARIABLE SETUP]

find_real_file.png

I hope someone can help me out 🙂 I am fairly new to javascript and service-now, but have experience in html5, php, sql

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will require email script for this

I hope you are aware on how to include email script in email body

Something like this

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

	var variableValue = current.variables.hvilken_model;

	var gr = new GlideRecord("question_choice");
	gr.addQuery("value", variableValue);
	gr.query();
	if (gr.next()) {
		template.print("Price " + gr.misc);
	}

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will require email script for this

I hope you are aware on how to include email script in email body

Something like this

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

	var variableValue = current.variables.hvilken_model;

	var gr = new GlideRecord("question_choice");
	gr.addQuery("value", variableValue);
	gr.query();
	if (gr.next()) {
		template.print("Price " + gr.misc);
	}

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur, 

This works perfect 🙂 thank you.

Can you also show me how to add the Text and Value from the price table to the template.print?

 

example result could be :

template.print(gr.text + "Price " + gr.misc); //gr.text prints NaN when I try now 😞

that should print :

iPhone 13 (128gb) Price 4.666 

This solved it 🙂 thanks for the help 🙂

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

    var variableValue = current.variables.hvilken_model;

    var gr = new GlideRecord("question_choice");
    gr.addQuery("value", variableValue);
    gr.query();
    if (gr.next()) {
		var pris = gr.misc;
		var grquest = gr.value;
		template.print("Model " + grquest);
        template.print(" Pris " + pris);
    }

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