Does Madrid support JavaScript string interpolation?

thomaskennedy
Tera Guru

I'm setting the params on a SoapMessage and I have one case where one param declared in my soapmessage may consist of the markup for multiple child elements.

SoapMessage:

</Narratives>
<EventValues>${event.rows}</EventValues>
<Polices>

The data may look like so:

<EventValue sku="abc" upc="12345"/>
<EventValue sku="def" upc="5678"/>

So I would like to do this:

var rows = (an array of objects)
var rows_data = "";
for(var index = 0; index < rows.length; index++) {
	var row = rows_data[index]; 
	rows_data += `<EventValue 
 		sku="${row[this.EVENT_VALUE_SKU]}" 
 		upc="${row[this.EVENT_VALUE_UPC]}" 
 		.../>`;
	}
s.setStringParameterNoEscape( "event.rows", rows_data);

But the editor says there is an illegal character on the line where my template begins. I believe it does not support interpolation in this context. Is this correct, and is there a way around it?

1 ACCEPTED SOLUTION

To the best of my knowledge (and ability to find) ServiceNow does not support what you are describing. 

From what I can find, ServiceNow only supports to to ES5: 

https://docs.servicenow.com/bundle/newyork-application-development/page/script/JavaScript-engine-upg...

and from what I can find, template literals were introduced in ES6: 

https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

So, I believe the answer is no, this is not supported currently in ServiceNow. 

If this was helpful, or correct, please be kind and remember to mark appropriately!

Michael Jones - Cloudpires

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

5 REPLIES 5

Michael Jones -
Giga Sage

This may just be an artifact of copy and paste, but:

rows_data += `<EventValue

That appears to be a ` character (Grave Accent) rather than a ' character (single quote)? It looks like you have the same at end:

.../>`;

 

Maybe try changing those to single quotes and see if that solves your issue?

If this was helpful, or correct, please be kind and remember to click appropriately!

Michael Jones - Cloudpires

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

It is the backtick, and that's intentional. According to my understanding template strings (in ES6, template literals) were added in ES5. Of ourse I can work around this using concatenation but the code is harder to read.

To the best of my knowledge (and ability to find) ServiceNow does not support what you are describing. 

From what I can find, ServiceNow only supports to to ES5: 

https://docs.servicenow.com/bundle/newyork-application-development/page/script/JavaScript-engine-upg...

and from what I can find, template literals were introduced in ES6: 

https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

So, I believe the answer is no, this is not supported currently in ServiceNow. 

If this was helpful, or correct, please be kind and remember to mark appropriately!

Michael Jones - Cloudpires

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

OK I will use concatenation.