How to read a file line by line in a task of my process

549 views
Skip to first unread message

J.M.

unread,
Oct 5, 2016, 9:08:28 AM10/5/16
to Fujitsu RunMyProcess Developer Community
Hi Team,


I'm building a process in which a user upload a txt file, and then I need to process it, and for each line save some important values.

My file looks like this:
.
.
.
123123:Pending
343242:Waiting
342324:On Air
.
.
.

I need to proces line by line and save the values on left and right of the ':'

How can I read a file line by line in a task of my process?


Thanks and regards.

Pankaj Kumar

unread,
Oct 6, 2016, 4:49:06 AM10/6/16
to Fujitsu RunMyProcess Developer Community
Hi,

Please use below free-marker code to read the file and get the each line split by new line character.

<#assign panContent = file_content("uploaded_file_id,"none")>
<#assign parray = []>
<#list panContent?split("\r\n") as x>
<#assign parray = parray + [x] />
</#list>
${parray}

Output will be an array where each object contain a line of the text file. (["123123:Pending","343242:Waiting","342324:On Air"])

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support


--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum+unsubscribe@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at https://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/c9cc37a9-88b9-4c2d-af3f-db4b79f5e4b7%40runmyprocess.com.
For more options, visit https://groups.google.com/a/runmyprocess.com/d/optout.

Pankaj Kumar

unread,
Oct 6, 2016, 4:51:44 AM10/6/16
to Fujitsu RunMyProcess Developer Community
Hi,

In addition to previous post:-

New line character is OS dependent, Please find the new line character details here.

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support

J.M.

unread,
Oct 11, 2016, 10:07:23 AM10/11/16
to Fujitsu RunMyProcess Developer Community
Hi Pankaj,


Thank you for the reply, your solution worked. However, now I have another problem.
I need to process the array with (["123123:Pending","343242:Waiting","342324:On Air"])
in order to update a collection, but I'm having problems building the record to insert.

Could you help me please?


Thanks again and regards.

> To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.

J.M.

unread,
Oct 11, 2016, 11:06:55 AM10/11/16
to Fujitsu RunMyProcess Developer Community, javiermm...@gmail.com
Hi again,


In addition to my previous post, my purpose is
1- read the file
2- obtain the values
3- check if there is an object in my collection with the data I just read (for every line)
3.a YES ---> update_object
3.b NO ---> save_object

I have the following (cont_file contains the array with my info. Following the example it would be like ["123123:Pending","343242:Waiting","342324:On Air"], but each coordinate of the array I'm using has more fields):

<#list cont_file as line>
<#assign data = line?split(":")>
<#assign record>
{"numSeguimiento":"${data[0]}","numTarjeta":"${data[1]}","fechaultcambio":"${data[2]}","estado":"${data[3]}"}
</#assign>
<#assign searchCollection>
${load_object( {"numTarjeta": "${data[1]}"}, "tarjetas")}
</#assign>
<#if searchCollection == {}>
${save_object(record,"tarjetas")}
<#else>
${update_field( {"numTarjeta":"${data[1]}"}, {"fechaultcambio":"${data[2]}","estado":"${data[3]}"}, "tarjetas", "true")}
</#if>
</#list>


My problem is how to check if load_object obtains a record of my collection or not.

Any idea?

Pankaj Kumar

unread,
Oct 12, 2016, 3:00:10 AM10/12/16
to Fujitsu RunMyProcess Developer Community
Hi Javier,

Please use the "list_objects" object method to get the data from the collection as "load_object" will return only one object if multiple object exist in collection based on your query.

Also the return type in "list_objects" is an array, so you can check the length to validate if any object is return by the method or not.

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support

To unsubscribe from this group and stop receiving emails from it, send an email to supportforum+unsubscribe@runmyprocess.com.

To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at https://groups.google.com/a/runmyprocess.com/group/supportforum/.
Reply all
Reply to author
Forward
0 new messages