Page 1 of 1

How can I access metadata in a script?

Posted: Sat Apr 04, 2020 12:04 pm
by bkromer
How can I access metadata in a script?
In my flow, there will be Metadata with path "[Metadata.Text:Path="/order/id",Dataset="Order",Model="XML"]" and "[Metadata.Text:Path="/order/reference",Dataset="Order",Model="XML"]" how can I access them in a script?

I tried this:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var data =	s.getString( xmp-path : "/order/reference", map ); // getString( xmp-path : String, prefix-map : Map ) : String
	job.log(1,"Data: "+data);
}

Re: How can I access metadata in a script?

Posted: Sat Apr 04, 2020 2:38 pm
by jan_suhr

Re: How can I access metadata in a script?

Posted: Sat Apr 04, 2020 2:47 pm
by bkromer
Thanks, I have read the docs but haven't found the right function. But I found a post in the forum.
The function I was looking for is: job.getVariableAsString

And if anybody else is struggeling with the syntax, here is my code:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var orderid = job.getVariableAsString('[Metadata.Text:Path="/order/id",Dataset="Order",Model="XML"]'); // path from Metadata
	var reference = job.getVariableAsString('[Metadata.Text:Path="/order/reference",Dataset="Order",Model="XML"]');
	var recordid = job.getVariableAsString('[Email.Body:After="id || ",Before=" || "]'); // or from EMail body
	job.log(1,"orderid: "+orderid+ "reference: "+reference+" recordid: "+recordid);
}

Re: How can I access metadata in a script?

Posted: Mon Jun 08, 2020 5:44 pm
by dkelly
Your code looks correct. I was able to retrieve values from the XML. Are you sure that you have 'picked up' the metadata and the dataset name is Order?

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <id>123</id>
  <reference>abc</reference>
</order>

Code: Select all

The variable '[Metadata.Text]' was evaluated to '123'
The variable '[Metadata.Text]' was evaluated to 'abc'