cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Problem with Pipeline Parameter in Mapper Snap

jhagist
New Contributor III

I am using a mapper snap to extract data from a json schema. This is the code from the expression

{id:$id}.extend($.fieldValues.map (elem => [elem.id, elem.type, elem.value]))

What I want to do is place this in a pipeline parameter (so can change this equation from the config file).

I canโ€™t figure out the expression syntax. Here is a screenshot of my latest failure. ๐Ÿ™

2018-07-12_10-53-43

7 REPLIES 7

Have you tried putting it in an expression library and then reference it there?

For example, I have an expression library file invItems.expr:
{
INVOICE_TARGET_DATE: _invoice_date || Date.now().toLocaleDateString(โ€˜{"timeZone":"EST", โ€œformatโ€:โ€œyyyy-MM-01โ€}โ€™)
}

and then i reference that in the pipeline:

lib.invItems.INVOICE_TARGET_DATE

tstack
Former Employee

As you found out later, the value of a pipeline parameters is a string. In order to evaluate it, youโ€™ll need to use the โ€˜eval()โ€™ function, like so:

eval(_field1)

Alternatively, you can put the expression in a file and import that file as a library (see Expression Library). Your library file would contain an object with a field that contains your function, like so:

{
    extract: doc => {id:id}.extend(doc.fieldValues.map (elem => [elem.id, elem.type, elem.value]))
}

You can then execute that function in your mapper with an expression like this:

lib.mylib.extract($)

jhagist
New Contributor III

Awesome that worked!

I did not try the library but it is an interesting concept.

Personal note for anyone else struggling with this. I am would suggest using the library suggestion or a parameter for the entire function. I spent a ton of time trying to variablize out the function and this path is much easier.

Another point. You canโ€™t use a variable with the json schemas in a mapper, it has to be a parameter.

Hope this helps! ๐Ÿ˜€