Once again large issue to be beginner and I am sure very simple one for wemMethods gurus. 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.
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 :*-)
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.
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.
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).
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, 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
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.
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.
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.
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?