Neuron ESB User Network

The Service Bus for the Connected Business

Can I use the For Each process step to go through a text file prior to converting to XML?

I have a comma delimited file that I am going to use the Flat File Parser to convert to XML.  The problem is one of the fields is a free flow entry and, at times, the users enter a comma in the field which causes the system to go bonkers because we end up with an extra field.

 

Can I use the For Each process step to go through the text file line by line to delete the errant commas?  If so is there an example of how to set it up, i.e., Collection Property Name, Item Property Name and how to refer to it in the code section?

Views: 144

Reply to This

Replies to This Discussion

The For Each process step will only iterate through a collection that exists in memory. You would need to first read the lines of the text file into something like a List<string> object using a code step, and put the list object into the context.Properties collection. Then you can pass that list to the ForEach process step and operate on each line.

To run the ForEach step, you would set the CollectionPropertyName property to the name of the list that you stored in the context.Properties dictionary. The ItemPropertyName property is set with the name that you want to use to reference the current item from the list inside of the loop.

For example:

  1. You can store the list of text lines as: context.Properties["FileLines"] = ...a list...
  2. You can set ForEach.CollectionPropertyName to "FileLines"
  3. You can set ForEach.ItemPropertyName to "CurrentLine"
  4. Inside of the ForEach loop, you can access the current line by retrieving the context.Properties["CurrentLine"] value.

Since the message is already on the bus looking like:

1,2,2014-01-20 00:00:00.000,3953,1061633,    XXXXXXXXXXXX8928,0

2,2,2014-01-20 00:00:00.000,3944,1061585,              TXSH 1,0

3,2,2014-01-20 00:00:00.000,6490,1061583,    XXXXXXXXXXXX4853,0

4,2,2014-01-20 00:00:00.000,4126,1061560,           Pickup By,0

5,2,2014-01-20 00:00:00.000,4126,1061560,   Antoine Alexander,0

6,2,2014-01-20 00:00:00.000,4126,1061560,        214-622-7792,0

7,2,2014-01-20 00:00:00.000,4126,1061560,     Guarantee Level,0

8,2,2014-01-20 00:00:00.000,4126,1061560,          15 minutes,0

9,2,2014-01-20 00:00:00.000,4126,1061560,  Target Pickup Time,0

10,2,2014-01-20 00:00:00.000,4126,1061560, 11:44 AM,0

Shouldn't I be able to reference it similar to:

context.Properties["FileLines"] = context.Data.Text;

to make my Properties?

 

Not exactly. You will need to use a code step to split the text using newlines. For example:

context.Properties["FileLines"] = context.Data.Text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

or

context.Properties["FileLines"] = context.Data.Text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

depending on whether your lines are terminated by LF characters (\n) or CRLF (\r\n). The latter may be the case.

RSS

Neuron ESB Product Support Forums and Communities

Latest Activity

Anupama Nair posted a discussion

Marketo Adapter Invalid Token

Hi,We are using the Marketo adapter to push account updates to Marketo. It works well for some time then starts failing with Invalid Token unless restarted. Is there a configuration that can be done so it can auto refresh the token when required?Thanks!See More
Nov 6, 2023
Sayantini Basak posted a discussion

Maximum payload size(REST API) for requests interfacing to NeuronESB

I am new to Neuron ESB and in our current scenario,We need to process batch transactions comprising of ~1000 records and send them to Neuron ESB for further processing. I would like to understand what is the maximum size of payload that can be transferred using REST interface to Neuron ESB.See More
Jul 22, 2022
Profile IconRobert E Dunie and Sayantini Basak joined Neuron ESB User Network
Apr 28, 2022
Profile IconDayanand, Frederic C, Steffen Greve-Oksfeldt and 1 more joined Neuron ESB User Network
Mar 16, 2022
Profile IconCam Vong and Mitja Luznar joined Neuron ESB User Network
Jan 27, 2022
Profile IconWill Hitzges, Chad Parsons, michael larsen and 4 more joined Neuron ESB User Network
Jun 11, 2021
Anupama Nair posted a discussion

ODBC stored proc polling with temporary tables

We have set up an ODBC adapter to poll a stored proc.We found that if the stored proc has a temporary table defined the rows returned are always 0.Any idea why this would be and what we can do to get around it?See More
Dec 14, 2020
Prasanth Kharade is now a member of Neuron ESB User Network
Dec 30, 2019

Badge

Loading…

© 2024   Created by Neuron Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service