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

Add incoming document to new file row

NAl
Contributor

We want the ability to write a document to a new row within a CSV file. This is only if the document meets certain requirements

Is this possible?
This article from a few years back suggests not and wondered if there has been any advancements

1 ACCEPTED SOLUTION

NAl
Contributor

Hello, hereโ€™s an update.
I found this article and used the expression to update the one on my Mapper snap. The resulting dat structure in the target path is the desired outcome!

Screen Shot 2022-01-20 at 17.42.35

This is great stuff so far. Iโ€™ll probably take a break now from testing and have some dinner before recommencing tomorrow. Thank you @j.angelevski for your patience.

View solution in original post

11 REPLIES 11

j_angelevski
Contributor III

Hi @NAl,

You can write a new row in the file ( I suppose you want โ€œappendโ€ ) but thatโ€™s supported only for FTP, FTPS and SFTP file protocols.

If you want to replicate this sort of logic, you can follow these steps:

  1. Create empty csv file ( not required )
  2. Read this csv file at the start of the pipeline even if itโ€™s empty.
  3. Read the new data from the other source.
  4. Use a โ€œGateโ€ snap to combine both inputs.
  5. Concatenate the input that contains the new data with the old data with a Mapper with the following expression: $old_data.concat($new_data)
    image
  6. Split the data with the newly concatenated data.
  7. Overwrite the initial file.

In this case, your new data will be always appended.

The pipeline should look something like this:
image

Thank you for providing a detailed outline. Iโ€™ve been away implementing this and looking at the right expressions to use to split/concatenate the data. Iโ€™ve managed to put the pipeline together however the Mapper snap isnโ€™t returning any data based on the expression provided:

Screen Shot 2022-01-19 at 15.13.34

This is a copy of the JSON message before it goes into the Mapper. There is currently no data in the csv file hence the blank message on input0

[
{
โ€œinput0โ€: [

],
"input1": [
  {
    "A": "X",
    "B": "X",
    "C": "60",
    "D": null,
    "E": "X",
    "F": "",
    "G": "X",
    "H": "X",
    "I": "1320159",
    "J": 1430047,
    "K": "X",
    "L": "X",
    "M": "X",
    "N": "X",
    "O": false
  }
]

}
]

If input0 contains the new data in your pipeline, you should write the following expression:

$input1.concat($input0)

This is working fine for me. Result:

[
   {
      "A":"X",
      "B":"X",
      "C":"60",
      "D":null,
      "E":"X",
      "F":"",
      "G":"X",
      "H":"X",
      "I":"1320159",
      "J":1430047,
      "K":"X",
      "L":"X",
      "M":"X",
      "N":"X",
      "O":false
   }
]

NAl
Contributor

Okay so weโ€™re getting there.
Iโ€™ve re-configured the Mapper and applied a few other changes but now the pipeline is returning an error:

Stacktrace: Metadata failed to load for โ€˜insert file location hereโ€™
Resolution: Check for URL syntax and file access permission

I read another article on here and wonder if it has something to do with setting up an Account in the File Reader Snap using Basic Auth?

The file is situated in a folder in SnapLogic under my username.