What is the syntax for string templates in scripts

JPing
Tera Expert

Hi All, 

Really simple question that I can't seem tot find the answer to.

I have a templated string stored in the message table "Hello {0}, you have completed the form...."

I want to retrieved this string 

and then present the message to the user with

gs.addinfomessage(message.format("Jeff"); 

I would have expected this to show the message "Hello Jeff, you have completed the form..." but the result is undefined. 

 

testing in  a background 

var message = "Hello {0}, you have completed the form....";

gs.info(message.format("Jeff"));

result:  undefined. 

is String.format() not a function that works in ServiceNow, what is the alternative?

 

I have seen Virtual agent use this, but I can't get to the underlying code to see the syntax. 

 

Thank You in advance.  

-Jeff

 

2 REPLIES 2

Rajat_Choudhary
Tera Expert

Hi Jeff,

There is a script include RecordToHTML you can create something similar to it.

Please refer this thread. https://community.servicenow.com/community?id=community_question&sys_id=8236d65edbe86f8067a72926ca96...

Hope this will be helpful and correct. if this helped you in someway.

Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary

The is sort of what I'm looking for but not quite. The source code does shed some light on a possible implementation. 

I think there is no OOB way of doing this and one would have to write there own method for this functionality. I have seen Virtual agent use this feature, so I wish I could just see the source code for the vaSystem to see how it was implemented. 

Thanks.