Showing posts with label Obj Browse in pega. Show all posts
Showing posts with label Obj Browse in pega. Show all posts

Thursday, 25 July 2019

How to export from Page List to excel in pega

How to export from Page List to excel in pega


Hi Friends, Today we will see how to export data from Page List to Excel sheet in pega.

Below is the List of steps we will follow to do this.
  1. Form Data in Page List
  2. Create Binary File Rule and Upload excel file contains page format of property
  3. Call Pega built in utility to export data

We have LeaveBalanceDays data Class which have list of Records. Now we will try to export these data to excel.



Below is the list of steps we will use in activity.



Pages and Class Tab:


Form Data in Page List:

 Before exporting data to excel we are forming the data in page list. In the Obj-Browse we are retrieving list of records and keeping in the Page List named EmpList.




Create Binary File Rule and Upload excel file contains page format of property:

We have to create a binary file rule which contains sample structure of data that we are going to export. Below screenshot is the excel file that we are going to upload in binary file.


Each EmployeeID in page will print in EmployeeID Column , Each FirstName in page will print in FirstName Column .

Save this file in your local machine in format .xlsx

Create binary file with Directory name as excel  and  file type as xlsx 



After creation of binary file upload the excel file template that we stored in local machine.



Save the binary rule.

Lets come to activity steps. MSOGenerateExcelFile is the built in activity to export data to excel we have to provide some required parameters to that activity.


For MSOGenerateExcelFile activity we have to pass 3 parameters.

  1. Param.FSFileName - Provide excel file name that we uploaded.
  2. Param.TemplateRFB - Have to provide binary file template name.
  3. Param.DownloadFile - true if we want to download file.

Check Pass Current parameter in method parameters.

Lets test our steps by run the activity.



Excel file got downloaded open the file and check whether data exported or not.



Data in data table exported to excel file. Hope this concept understood . If any queries ask in comment friends😊

Note: In some pega version MSOGenerateExcelFile activity may through nullpointer exception. If so replace java step in MSOGenerateExcelFile with Below code and try:


String xlFileName = tools.getParamValue("FSFileName");
PRFile xlFile = new PRFile(xlFileName);
java.io.OutputStream xlOS = null;
java.io.InputStream tempIS = null;
byte[] tempBytes = null;
boolean projectSizingPresent = false;
String strWorkObjectRef = "";
ClipboardPage objRefPage = null;
java.util.ArrayList sizingList = new java.util.ArrayList();
try {
  
        tempBytes = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(tools.findPage("TemplateFile").getString("pyFileSource"));
  
  
    tempIS = new java.io.ByteArrayInputStream(tempBytes);
    java.util.Map xlZipEntryMap = null;
  
        xlZipEntryMap = com.pegarules.generated.pega_appdefinition_excelintegration.DCOXLGenerateZipEntryMap(tempIS);
  
    xlOS = new PROutputStream(xlFile);
    com.pegarules.generated.pega_appdefinition_excelintegration.DCOzipEntryMapToStream(xlZipEntryMap, xlOS);
    if (tools.getParamAsBoolean(PropertyInfo.TYPE_TRUEFALSE, "DownloadFile")) {
        pega_rules_default.downloadFile(xlFile.toString(), tools, true);
    }
}
catch (Exception e) {
    oLog.error("Error in parsing Excel file " + xlFileName, e);
    //throw new RuntimeException(e);
    tools.getStepPage().addMessage(e.toString());
}
finally {
    if (xlOS != null) try { xlOS.close(); } catch (Exception e) { }
    if (tempIS != null) try { tempIS.close(); } catch (Exception e) { }
}


Sunday, 25 November 2018

How to Insert Records into Table in Pega

How to Insert Records into Table in Pega


I was created an Local Data Type with Zero Records, Lets see how to insert data in to Table.

I have created a flow , in the first assignment I get Employee Information .In  the flow action post action I mapped an activity to enter the information what we get in the first assignment into the table.


Now add activity to flow action post action.

Activity Methods used to insert data to table.

Pages and Class Tab:

In this activity we are inserting the data in to the table, We have all the data except EmployeeID, We have to get incremented  EmployeeID for each employee.

EmpCaseInfo page to store Case Details what user provide in the form.
MaxRecords page to store existing records in table.

Obj-Browse to retrieve all the data which is already present in the table. We are using this step to get the count of the table, Now we can add 1 to get next employee id for current Case.
In the property-set , I copied the data in Primary Page(pyWorkPage-TGB-HRApps-Work) to EmpCaseInfo(TGB-HRApps-Data-EmployeeInfo) Page.


EmployeeID is calculated by record count of the table +1, if 10 records are already present then pxResultCount will be 10, for our next record we are providing EmployeeID 11.


Obj-Save to save the data into Table.

Lets test the activity by run the flow and enter test data.

I am providing this data and click submit.

Now you can see first record is inserted.

Lets provide another one data.
After processed this case, you can see a new record is added in table.

That's all insertion of data into table. If you have any doubt ask in comment.

Monday, 15 October 2018

Obj-Filter in Pega

Obj-Filter in Pega

Hi Friends, Today I learnt about Obj-Filter , I will share My Knowledge to you.

From the Method Name itself we can guess the functionality of this Method. Your Guessing is correct. This method is used to filter records .

Let we see in practical. Below is this List of Records in Class TGB-HRApps-Data-Courses

Now we will use one activity to retrieve those records from table and Filter based on some condition.

This is the activity I created in TGB-HRApps-Work.


I added 3 steps in activity

  1. Page-New to store all my data while processing.
  2. Obj-Browse  to retrieve records from Database table
  3. Obj-Filter to filter the retrieved Records.

Here is the Pages and Class Tab


I retrieved all the records from Table Using Obj-Browse Method.


Now Up to this step It will retrieve all the records from Database On seeing the Clipboard U can Get some idea.

Next in Obj-Filter I added a when condition to retrieve only Records having Department "All"

In Obj-Filter Method,
In List Page We have to provide the Page List in which the records are available.
In Result Class We have to provide the Class in which the page list is belongs to.
In When condition we have to provide a when rule , In which we have to write filter condition.

Here is the When rule 


This When for  Filter only the Records Which Contain Department "All"

Record Which satisfy the When rule only remain in the page, other records will be removed.

So  Records having Department only remains in my page, Lets execute and See the result.


Now u can see there is 6 records in the Course Records Page.

It contain only the records Department contain All..

Thank u Friends for Reading.. See u. :)

Wednesday, 29 August 2018

Primary Page in pega

Use of Primary Page in pega


In most of the case we will use Primary page in pega activity. What is the use of Primary page and why we have to use primary page???

Primary page is a page in pega, which refer to the current rule class name.

Now our requirement is to get the employee details for the given employee id. 

How to acheive this?? First we have to create one flow in that flow , in first section we have to get the employee id . In action tab of EmployeeID property we have to post the value to clipboard and then call one activity in that activity we have to use obj-Browse method to get the employee details. 

Lets see how to achieve this.

Our flow look likes

Our section look likes


In the First Dynamic layout we have one Employee ID property to get the employee id . On change we have to post the value to clipboard and then call one activity.



U can ask , Y we have to use Post Value , the answer is to post the property value to clipboard.  Now in our scenario. Once I changed the EmployeeId property with some value that value will be send to clipboard using this Post Value.


Then on change of value in EmployeeID property we are calling one activity "RetrieveEmpDetails"

there we retrieve employee details.

Now In first step , I created Page-New step to create one page in clipboard with name TempEmpDetails.

TempEmpDetails refer to class where my local data table is there.


In second step, I added Obj-Browse, to retrieve values,

Now I used page Primary. in this time primary refer to "TGB-HRApps-Work", as I told already Primary == class of the rule.(activity is in class TGB-HRApps-Work)

So in run time EmpID is refered from pyWorkPage , this is because pyWorkPage is also refer the current rule class .

Now we run once our flow and check whether our activity works fine or not.


Now lets run the flow.

Now I gave 2 in employee id field. so now see our clipboard whether TempEmpDetails have value or not.


So its working.  I think U understand how to use Primary Keyword in pega activity. Primary refer to class of the rule.

If any Doubt ask in comment 😊