XmlDocument class

Post Reply
tdeschampsBluewest
Newbie
Posts: 3
Joined: Tue Jun 01, 2021 11:57 am

XmlDocument class

Post by tdeschampsBluewest » Fri Jun 17, 2022 3:01 pm

Since Legacy Scripting won't be supported anymore in 2024, i'm trying to switch (no pun intended) to the new switch 2022 Typescript mode for variables in mode "text with script expression".


Before, for using a Switch variables, we used job.getVariableAsString("[SOMETHING]", s);
But now that this is no longer available we have to go through much more complex bypasses.
I tried to use the XmlDocument class but without success and can't find where i'm wrong :

Here is an example with a simple dataset,

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<root>
	<tag1>Hello world!</tag1>
</root>

Here is my script :

Code: Select all

// Your imports here

async function getXpath(job: Job, dataset: string, xpath: string): Promise<string> {
	let result:string|number|boolean;
	try {
		const datasetPath = await job.getDataset(dataset, AccessLevel.ReadOnly);
		const XML = XmlDocument.open(datasetPath);
		const NSmap = XML.getDefaultNSMap();
		const evaluation = XML.evaluate(xpath, NSmap);
		result = evaluation;
	} catch (e) {
		result = e.message;
	}
	return JSON.stringify(result);
}

// Do not remove calculateScriptExpression function. It must return a promise to the property value.
async function calculateScriptExpression(s: Switch, flowElement: FlowElement, job: Job): Promise<string> {
	let result= ""
	const dataset = "Log";
	const xpath = "/root/tag1";
	result = await getXpath(job, dataset, xpath)
	return result
}

The typeof result in the main function is "undefined"

Every bit of Help will be appreciated! :oops:

tdeschampsBluewest
Newbie
Posts: 3
Joined: Tue Jun 01, 2021 11:57 am

Re: XmlDocument class

Post by tdeschampsBluewest » Mon Jun 20, 2022 11:49 am

Additional note:
The script does not return an error, and does not go into the "catch" of the getXpath function.
I tried with different ways to write the Xpath (without the first /, with double "//")

Post Reply