How can I access metadata in a script?

Post Reply
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

How can I access metadata in a script?

Post 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);
}
Benjamin
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: How can I access metadata in a script?

Post by jan_suhr »

Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: How can I access metadata in a script?

Post 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);
}
Benjamin
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: How can I access metadata in a script?

Post 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'
Post Reply