Find installed connect template by name

Working within the workflow, I want to dynamically select the template for a Create Email Content.
I am able to do when the name of the template matches exactly a metadata value …

image

But now I would like to do it when the template STARTS with that metadata value … “2001001_AutoPay_Cancel.OL-template”

I am attempting to create a script to select the name. I am stuck on how I “Search” the list and find a template that starts with “2001001”. I got this far…

var allTemplates = Watch.GetResources(“OL-template”);
Watch.Log(allTemplates, 3);
var myObj = JSON.parse(“[” + allTemplates + “]”);
Watch.Log("template count = " + myObj.length, 3);
var foundTemplate = myObj.find(x => x.name.startsWith(“2001001”));
/*Watch.Log("template found = " + foundTemplate, 3);
*/

The “find” method breaks. Not sure if that is valid, or a better way to achieve this. Any help is appreciated.
Thanks.

Hi @bradnowak,

I suppose that you cannot make use of the find method in JScript. Instead you can make use of a for loop, like for example:

var foundTemplate = "";

for (var i = 0; i < myObj.length; i++) {
	if (typeof myObj[i].name !== "undefined") {
		if (myObj[i].name.indexOf("2001001") == 0) {
			foundTemplate = myObj[i].name;
			break;
		}
	}
}

Thanks. That worked. I appreciate the JavaScript assistance.