Forum Discussion

darshthakkar's avatar
darshthakkar
Valued Contributor
4 years ago
Solved

Ingesting dynamic values in XML generator snap

I’ve 10+ columns which needs to go inside an XML generator snap; out of which, there is 1 column which has none to single to multiple values. For each of these records, how can I dynamically pass it to XML generator snap?

These values can be considered as web links that needs to be wrapped as a hyperlink and a title needs to be given (probably in XML generator as it’s dynamic); title is based on the weblink as the weblink has been formed with the concatenation of certain fields that will be used as a title.

For example, weblink is https://www.google.100snapLogic.com, title would be 100.snapLogic
Just for everyone’s convenience, weblinks are different for each record and you guessed it right, title would be different too.

100 and snapLogic used in the weblink are values of different cols and we do have access to those column values.

  • siwadon's avatar
    siwadon
    3 years ago

    It depends. If your $ID are numbers, you can change the expression to

    [100, 110, 300].indexOf($ID) != -1
    

    I don’t understand your last question about Mapper. Since you mentioned using the Filter snap, this is for the Filter expression setting.

  • I used the dummy data below to create a working solution.
    Input: 

     

     

    [
        {"txt":"abc"},
        {"txt":"efg"},
        {"txt":"c - abc"},
        {"txt":"c - xyz"}
    ]

     

     

     
    In the pipeline properties, I've defined a parameter filterValues that will contain the strings based on which you want to filter the records.
    Use the below expression in the filter snap:

     

     

    JSON.parse(_filterValues).map(x => $txt.contains(x)).filter(y => y == true).length == 1​

     

     

     
    The result based on the input above looks like this:
    The record that doesn't have the matching string defined in the filterValues parameter will be omitted.
     
    Hope this helps!
     
    Cheers😉,
    Abhishek
     
  • darshthakkar - My solution is pretty similar to what Abhishek_Soni37 provided.  

    I would recommend that you not use JSON.parse() for every record.  It can be fairly taxing on your CPU depending on data volume.  If you want to remove the hardcoded reference to the array of values to search for, I recommend you look at Expression Libraries.

    Hope this helps!

     

5 Replies

  • Hi @smit66,

    Yes you can convert datetime to unix timestamp with a Date Time Extractor snap.
    First map the datetime in mapper:

    Then use a Date Time Extractor snap:

    Result:

    • smit66's avatar
      smit66
      New Contributor II

      Thank you for your quick response.

  • You can also do it more simply with this expression in a Mapper:

    Math.floor(Date.now().getTime() / 1000)

    • smit66's avatar
      smit66
      New Contributor II

      Thanks for your response, I’m currently using this solution.