LOOP and writeToFile issue

Hi Guys,

Once again large issue to be beginner and I am sure very simple one for wemMethods gurus. :slight_smile: I have created a flow that reads in a flatfile content line by line. Now I need to extract all lines one by one that start with an A and save them in a text file. That text file will be later used as an attachment. I am getting the FlatFile in and parsed correctly (thank’s to Tim Conner and Ram) but now I am having trouble extracting all lines that start with an A via loop.

The flow is contracted as follows:

-SEQ
–SEQ
—SEQ
—>getFile
—>convertToValues
—LOOP$default: LOOP over /A/Attachment
—>writeToFile

Document:
FFSDT

FlatFileSchema
FFS

The document contains simple layout. I need to loop over and save only lines that start with A. How can I loop over only that line? I must be putting in incorrect values in in-array and out-array.

in-array: /A/Attachment
out-array:/A/Attachment

I tried multiple things but nothing seems to work. I know I am making some small mistake that I don’t see.

Any help greatly appreciated!

Thanks,
Sebastian

pckg
EFT2.zip (9.2 k)

test file
flat_file_data.txt (2.8 k)

I am certain that something is incorrect with the loop. When I place the writeToFile outside the loop one level higher the first A line is being fetched in. The problem is using the A line to loop thru. How can I accomplish that :*-)

Many Thanks!
Sebastian

My test file has 17 lines of A. I have changed the in-array to /Results/A and it looks like the loop is looping 17 times b/c in Re sluts I get the Successful flag show up 17 times for that loop but for some reason still can’t get the data out into a file.

Any help appreciated.

Thanks,
Sebastian

Sebastian,

Move your pub.file:getFile statement inside the second (try) sequence. Your sample service is ending successfully after processing that statement since your outer sequence is configured to exit-on-success.

Mark

Try using a regex condition, you can use this expression /A.+/ For more information read the Developper Guide Documentation.

BTW I tested this with your flatfile data and it seems to work (you should remove your Header Info first), this expression will search Any line starting with A until the end of the line (depending on your data of course).

hth

Set the input array of your LOOP statement to “Results/A”. Then map the value of the Attachment field to the fileContent input parameter of your writeToFile statement. Note that this should be indented so that it is “inside” your LOOP block.

This seems like a very awkward way to simply send an email. First the file is formatted for printing not for automated processing, second, if just wanted to extract a part of the file and write it to another file, there are a thousand ways to do this in a scripting language without using IS.

Also, a best practice is to never use code samples in your own packages. If you find something useful, make a copy of if in your own package or utilities package and modify it to ensure that the code sample meets your coding standards (error handling, comments, etc.).

Mark

Hi Guys,

Mark, I agree that what I am trying to do could be done using simple script out side IS but that is out of my hands. Orders are use WM. Basically what I am trying to accomplish per my requirements is. Use E line for email S for subject, B for Body of the email and A for Attachment.

As per your suggestion I have mapped the Attachment field to the fileContent but still not getting the data in. I am getting the success flag 17 times so the loop is working correctly just no data and no written file.

Hmmm why is that? Everything is mapped correctly? I should be getting written file with data from the mapped field?

I will keep trying to figure this out but if anyone could take a look to see if I am on the right track that would be great! Will save me some headache and a couple of gray hairs :slight_smile:

Many Thanks,
Sebastian

pckg
EFT2.zip (9.2 k)

test file
flat_file_data.txt (2.8 k)

Hello,

Yemi Bedu


  1. Aa ↩︎

  2. Bb ↩︎

  3. Ee ↩︎

  4. Ss ↩︎

Just realized I have attached old pckg in prev. msg. Here is the right one if any one is able to help me out. Thanks!!

new pckg
EFT2.zip (8.5 k)

test file
flat_file_data.txt (2.8 k)

Thanks Yemi… Will give it a try.

Yemi, it looks like a complete rework. Are you saying my current setup is incorrect and I will not be able to get the file attachment created?

Here is what I got. I am unable to get the attachment written. Got the loop to loop over the data that should be written but can’t get the actual data written to a file. I have mapped the A field to the fileContent but the file is empty.

-SEQ
–SEQ
—SEQ
—>getFile
—>convertToValues
—LOOP$default: LOOP over /Results/A
—>writeToFile
—>SMTP
–SEQ (Error Hangling)
–>getLastError
–>SMTP

At this point I have ran out of ideas as to what I can do. If any one can help please do. Got only 2 more days to have it done. :frowning:

Thank You to All,
Sebastian

Hello,

Yemi Bedu

At this point I am not sure if I have correct flow setup.
Case:
Flat file is FTPed to webMethods server. Part of that file needs to be emailed as an attachment.

Flat File

H<header>
E<email>
S<subject>
B<body>
B<body>
A<attachment>
A<attachment>
A<attachment>
E<email>
S<subject>
B<body>
B<body>
A<attachment>
A<attachment>
A<attachment>
T<transid>

E is used for Email, S for subject, B for body and A should be an attachment. There can be multiple emails like that within one flat file.

I have created Flat File Schema for the given flat file and created the following flow. But I know something is not right b/c its not working. I am not getting the extract from the flat file.

-SEQ
–SEQ
—SEQ
—>getFile
—>convertToValues
—LOOP$default: LOOP over /Results/A
—>writeToFile
—>SMTP (Send Email with Attachmetn)
–SEQ (Error Hangling)
–>getLastError
–>SMTP (Notify Support)

Any input appreciated.

Thanks,
Sebastian

What happens when you execute your writeToFile service by itself with a dummy fileContent value? If you can loop over the data correctly and write it out to the console using a debugLog message, you should be able to write it to a file.

Break the problem down into smaller chunks. Get each chunk working and the reassemble for a complete solution.

Sounds like you are on the right track and pretty close, but are missing something simple. What errors are thrown when you run your service?

Mark