XmlDocument class
Posted: 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,
Here is my script :
The typeof result in the main function is "undefined"
Every bit of Help will be appreciated!
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!