Thursday, 25 April 2019

POC for Creating work object by listening Microsoft Excel, Generating PDF and Attaching PDF to the work object

1. Problem Definition:        

Create a PRPC work object using the data provided from excel sheet through File Service (Delimited Parse Rule), generate and attach a PDF to the work object.

2. Solution overview:

Here, Account Information is placed in excel sheet and saved in csv format in a specific folder.  The Listener listens the specified folder and when ever it finds a new *.csv files, file Listener sucks into PRPC and it will call the service method (Rule-Service-File) in which we will map the entire file to Clipboard through Delimited Parse Rule instance.  This process will follow for all the rows in the excel sheet and creates a new work object for each and every row, generate and attach a PDF to the work object with the work information. 

3. Prerequisites:

           
1.      Have the application built ready with the necessary properties like First name, EmpID, EmailID etc, so that we can map the information from excel sheet to properties and work flow.


4. Creating required Instances for work object creation:

4.1:  Create an instance of Data-Admin-ServicePackage

Use a Data–Admin-Service Package instance to define a package name, define access for listeners, and support deployment of services.

The following are the screen shots of Context tab and Methods tab.  No specific changes are required in rest of the tabs.

Mention the Rule-Service –Type as Rule-Service-File in the Methods tab and save the instance.

4.2:  Create an instance of Rule-Service-File

We have to mention the service package name, class name and method name while creating.

In the service tab we will mention the class name and the page name on which the service activity works.

In the Method tab we will mention how we will accept the input as a file or as a record.
now we need to take one record at a time as input.  We will specify the carriage return and new line as the record Terminator.




In the Request tab we will mention:
How the input is mapped here we are mapping the incoming record to properties using ParseCsv Rule-Parse-Delimited. 

The service activity name which to be run after mapping.  Just create the activity we will edit that afterwards.




4.3:  Create an instance of Data-Admin-Connect-FileListener

complete the details in properties tab as followed below

Under the Listener Nodes section you will specify the network name of the server host node or nodes where this listener is to run.

Below Listener Properties section we will specify the path of the folder where we keep the csv file, the type of file here it is csv, no of threads we want usually we select one.

 Each listener will linked to Rule-Service-File rule.  For Service Package select the first key part of a Service File rule instance which is the name of Data-Admin-ServicePackage.  For Service Class select the second key part of a service file rule.  For Service Method select the third key part of the service rule.   You can also select from smart prompt.



4.4:  Editing the InvokeFlow activity

In this activity we need to create pyWorkPage, set the properties on the pyWorkPage from ServicePage (AlertServicePg), creating work object by calling Work- Add method on pyWorkPage.
Step1: Create pyWorkPage.
Step2: Now assign the properties on pyWorkPage from AlertServicePg.
Step3: Here call Work-. Add activity.
Step4: Then Save.
Step5: And then Commit the changes.




5. Creating required Instances for PDF attachment:

5.1:  Viewing fields in PDF

If we want to know what are the Text Fields, checkboxes, buttons etc available in pdf, for this we need to open the pdf and follow the steps shown in screen shot.

We need to create two rules to work with PDF
1) Rule-File-eForm
2) Rule-Map-eForm
We can create these rules through eFormRules accelerator or manually


5.2:  Manual Creation

5.2.1: Create an instance of Rule-File-eForm

Rule-File-eform:  holds the PDF forms that process commander uses as templates for new PDF forms.
We have to navigate Upload File button through which we can upload the sample PDF document. Once the file is uploaded a message is displayed with success status else display the failure message .

5.2.2:  Create an instance of Rule-Map-eForm


Rule-Map-eForm : provides data mapping for PDF forms fields, matching them to process commander properties. Left side under Field Name we will get the fields available in the PDF in smart prompt and on the right side under Property we will get the properties in the smart prompt.


5.3:  By Using Accelerator

The following screen shots show how to create these rules through accelerator.

In the dashboard we will find Create E-form Rules Accelerator

We will enter description of the rules and click start

Now we will specify the class name in which these rules are created and ruleset name and the version 

In this step We will give the complete path of the PDF file and click next.

Here we will select the fields which we want to map to the properties on the clipboard and click next.


Here we will map the PDF fields to Clipboard properties and click next.
then it will ask for review and save.


A list of rules will be displayed, click finish button to complete the process  

5.4:  Creating  an instance of an Rule-Obj-Activity


MapClipboardToPDFForm  Activity

This activity we are calling three other activities which will create pdf, attach the pdf to the work object and save the pdf on the server. We need to have details of the parameters and explanation for each activity below in detail.

@baseclass.GenerateEForm – Creates PDF forms, populating the fields with property values from the clipboard. It needs three parameters


MapPurpose: The key to the eForm map rule to use. (We will discuss about map rule next) An eForm map rule has two keys, the Applies to class and the Purpose name. The MapPurpose property supplies the second key, the Purpose name.

TargetEFormPage: The name of the page of class Code-Pega-eForm on which the results are stored. This page must already exist

SourceEFormPage:  The name of a page of class Code-Pega-eForm that holds a previously generated PDF form that is still on clipboard and that you want to update.


Work-.AttachEForm – Attaches a PDF form or document to work object.


PageName: The name of the work object page, typically pyWorkPage.
InsHandle: The work object ID: the value of the work object's pzInsKey property.
Filename: The name to use for the file.
eFormPage: The name of the eForm page that contains the PDF file to attach to the work object
pyNote: A value for the pyNote property. Typically a brief description of the file attachment.

WriteEFormToFile – saves the PDF file to the directory specified, using the file name specified in the Filepath parameter


We have to include this activity at the assignment where you want to attach the pdf. That Mean,  in the flow action before activity or after activity)



6.  This is test time Test the work object creation by placing the excel sheet in the folder.

Initially start the Listener:
Go to PRMonitorServlet and click on the Listener status link.  There u will find the list of available listeners here, and then start the Alertfilelistner.





Save the excel file in .csv format and place it in the folder specified in listener. When the listener listens to the file, the request count is incremented (refresh the screen once).  You can see the work objects instances are incremented. And also check for that work object ID in PRPC, open it, process the work object and check for the PDF as attachment.

1 comment: