Hi again!
For an app, the entrypoint is not the same, and the output should/will be different.
In a script expression, you always "return" something.
In an App, you'll need to store the result in a way switch will be able to read it afterwhile.
Code: Select all
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(`string(${xpath})`, NSmap);
result = evaluation;
} catch (e) {
result = e.message;
}
return result.toString();
}
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
const dataset = await flowElement.getPropertyStringValue("datasetName"); //"Xml"
const sectionKey = await job.getPrivateData('\"sKey\"]');
const xPath = `/Job/Something[${sectionKey}]/Key`;
const result = await getXpath(job, dataset, xPath);
const newPrivateDataName = await flowElement.getPropertyStringValue("newPrivateDataName") as string; //"My Private data"
await job.setPrivateData(newPrivateDataName, result);
await job.sendToSingle();
}
Do not forget to "transpile" your Typescript, if you work with an app. The command line should be :
Code: Select all
SwitchScriptTool.exe --transpile PathToYourTypscriptFolder
If you work with VS code, you can automate this, with runOnSave (emerald walk) addon and by adding thoses value in your settings.json :
Code: Select all
"emeraldwalk.runonsave": {
"autoClearConsole": false,
"commands": [
{
"match": "\\.ts$",
"cmd": "cd ${fileDirname}"
},
{
"match": "\\.ts$",
"cmd": "SwitchScriptTool.exe --transpile ${fileDirname}"
}
]
},