Discussion

Replicating File Service functionality

We have a requirement where a User should be able to uplaod an XML file and on Submit the File Service needs to be invoked. We were successful in achieving the similar functionality by configuring the File Listner and File Service. What we want now is that the User be shown a page where he can upload a file and internally call the File Service to process this file. How can this be accomplished?

Thanks in advance.

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

July 1, 2010 - 12:59pm

Hi,

I have the similar requirement and tried the file service. By using the file service i am able to parse the CSV files. But how do we invoke the same from a pega activity?

In my case, users will upload the files to work object. I need to read these files, parse them and validate them.

Are you able to solve this issue?

If you know the solutions or steps, can you please let me know...If you want me to call to discuss this issue I will ...

Thanks

Pega
July 2, 2010 - 3:18pm

Any parse rule applied in the file service form can also be applied in an activity step by using one of the Apply-Parse- methods to a param val, property val, or local var. I guess the only potential issue is if you are doing record-at-a-time processing in the file service. Then you would need to approximate this in your activity by first breaking down the value into individual records before applying the parse rule.

July 7, 2010 - 6:24pm

I was not able to find a way to invoke the same activities as the Service-File rules. I think these rules call a number of functions in the Public API rather than invoking Activities.

As an alternative there are a couple of other ways you can do this:
- Use a Connect-File or custom java function to write the file's contents to a location being watching by the OOB Service-File rules
- Roll your own custom activities that invoke some of the same functions as the CSV parser built into the service-file rule. This requires you to load the contents of the file yourself, split the contents into individual lines. Then there are two functions you need to call parseCSVHeader (to parse the first line, this puts the tag names in the .pyTagList property) then call parseCSVDetail on the remaining lines. This will require you to have a class that models the contents of the file -- one property for each column where name of the property matches that of the column.

Can others come up with simpler solutions?

Rob

quote:


Originally posted by TANDP

Any parse rule applied in the file service form can also be applied in an activity step by using one of the Apply-Parse- methods to a param val, property val, or local var. I guess the only potential issue is if you are doing record-at-a-time processing in the file service. Then you would need to approximate this in your activity by first breaking down the value into individual records before applying the parse rule.

July 8, 2010 - 8:40am

Hi Robert,

Yes You are right. Initially we have to read the file that is attached to the work object(which is encoded in base64 format), store the individual records(lines) in the clipboard as various pages. Then we can loop through each record and parse the CSV records using parse rules for each page(line) and validate them.

I am clear on how to parse and validate. Only issue I am trying here is reading the file from work object, decode it and break it into different lines. This I will try using the Java.

The other thing I noticed in pega is:

When we decode the following lines:
Testing 1
Testing 2
Testing 3

using the decode function provided by Pega, it gives us Testing 1 Testing 2 Testing 3. Not sure why there is no carriage return/line termination character is not coming in the reply.

I opened a service ticket with pega for the same.

Thanks for your time.

July 8, 2010 - 3:29pm

No need for custom java here. You can use and activity and/or declarative processing to do this:
1. Set the whole file contents to a Text Property
2. (optional -- this can be done in-line with an activity doing step 1) A R-D-OnChange watches this property and calls an activity
3. The activity splits the contents of the property and adds the individual lines to a text value list that has one line of text in each row of the list.

Rob

quote:


Originally posted by ANDHAVAS

Hi Robert,

Yes You are right. Initially we have to read the file that is attached to the work object(which is encoded in base64 format), store the individual records(lines) in the clipboard as various pages. Then we can loop through each record and parse the CSV records using parse rules for each page(line) and validate them.

I am clear on how to parse and validate. Only issue I am trying here is reading the file from work object, decode it and break it into different lines. This I will try using the Java.

The other thing I noticed in pega is:

When we decode the following lines:
Testing 1
Testing 2
Testing 3

using the decode function provided by Pega, it gives us Testing 1 Testing 2 Testing 3. Not sure why there is no carriage return/line termination character is not coming in the reply.

I opened a service ticket with pega for the same.

Thanks for your time.


July 9, 2010 - 5:54pm

Hi All,

Finally I am able to resolve this issue by decoding the file contents, reading and storing them in the clip board, parsing them.

Thanks for all your time in this regard.

June 15, 2010 - 6:17am

Can't you directly call the activity mentioned in Rule-Service-File instance? Why do you need to invoke Rule-Service-File instance?

Pega
June 15, 2010 - 8:11am

I *think* what you want is to use the stardard HTML file upload form element, then process the file using the same XML processing used by the file service. If the file service is calling the XML parse rule directly, you will need to write a new activity that has an Apply-Parse-XML step in it. The uploaded file content will be available in the pxRequestor page in the clipboard.

September 8, 2011 - 2:47pm

Hi ,

I am able to read the CSV file and map the data to a text property , but i am having some difficulty in parsing the data .

I have a CSV file with 5 columns and 20 rows . The first row would be the header and hence would reflect the property names in the page . The rest will be the actual data and should be mapped to the property values . Ideally , I would want to have a pagelist with each row as a Page .

I am able to get the desired output with use of a listener , but unable to get the same with an activity. I am trying on the lines of the csvheader and csvdetails and also the taglist .. but confused on how to do the iteration as Pega is not able to figure out the end of the row.

PLease suggest .

Suprit

January 4, 2011 - 4:38am

Hi,

I am able to visualize the solution, can you please tell me the procedure on how were you able to read, parse the file uploaded by the user. I have a similar requirement.

Vasanth

quote:


Originally posted by ANDHAVAS

Hi All,

Finally I am able to resolve this issue by decoding the file contents, reading and storing them in the clip board, parsing them.

Thanks for all your time in this regard.