Showing posts with label Activity in pega. Show all posts
Showing posts with label Activity in pega. Show all posts

Monday, 15 February 2021

How to download Base64 pdf file by using Pega Activity

Hi Friends, In this post we will see how to download a file which is in base 64 encoded format.


URL to get encoded format of a file : https://base64.guru/converter/encode/file


Selected a pdf file from my local system and click encode file to base 64 button to get encoded data of the file.

Created a sample activity VerifyWork, in that called an pega activity named View of Code-Pega-PDF class.






This activity use is to download the base 64 format pdf file .

For this activity we have to provide 2 parameters,

PDFName - in which name the pdf file should download
PDFDocument- base 64 format of pdf file.

Added Java step to decode base 64 into byte array.



Java code:

String S = tools.getParamValue("PDFDocument").toString();
byte[] byteArray =  new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(S);
tools.putParamValue("PDFDocument",byteArray);

Lets run the activity and verify our work.



We can see the pdf file is downloaded on running the verifywork activity. 

Hope this topic understandable to everyone. Comment if you have any doubts.

Sunday, 19 April 2020

Page List expression Part 2

Hi Friends, In this post we will see below Page List expression.


PDN help:

https://community.pega.com/sites/default/files/help_v718/definitions/p/pagelist.htm



IsInPageListWhen(whenName, lookIn) -  this expression will return true when any one of the pages in page list  evaluates to true. 


Below is the list of instance in Courses table.



Now when we have to use this expression?

If our requirement is to find  any records having department as engineering  then we can use this expression.

How we can do that.

In the when rule we can check .Department = "Engineering"


Activity:



Obj-Browse: to browse list of records from Course table.



In the property set added the expression to check any pages have the match.



Now the above expression will become true when any pages data evaluates to true against the when rule CheckInPage.

When rule: CheckInPage




Now run the activity and check the result in Tracer.



In tracer we can able to see total 10 records retrieved from table. then the when rule become true.


So lets check the parameter(RetValue) in Parameter Page.



Value is true in Tracer.

So this expression completed.

---- **** -----


IsInPageList(lookFor, lookAt, lookIn) - This expression will provide return value true/false.

LookIn -  pagelist name in which we have to check.
LookAt- Property in Page.
LookFor- which value we have to check in the property.


In Page List CourseList.pxResults we are checking any pages having department = engineering.
In tracer we can able to see the parameter value as true.


Other expression we will see in next post. If you have any doubt ask in comment.😊

Thursday, 26 March 2020

Count In Page List Pega expression


Count In Page List Pega expression

Hi Friends, today we will practice the Page List expression provided in the below Pega help URL.

https://community.pega.com/sites/default/files/help_v718/definitions/p/pagelist.htm

Wrote a sample activity in work class to browse the list of pages from Courses data class.



Courses Data table


countInPageList(LookFor, LookAt, LookIn)


This expression will provide the Match count . 

LookIn- PageList name in which we want to search.
LookAt- which property we have to search for value.
LookFor - Value what we have to search in the Property.


Now If I want to get the Number of records having Hours = 2 , then I will use this expression .
 



From the table we can see for 4 records hours is 2.

In Property-Set added expression to get the count of pages which having hours 2.

Value will return in Count Parameter.


Lets run the activity and check the result in Parameter page.

Activity ran and traced 


In Event Line 7, we will check the parameter page.

We can see the result as 4 in Count Parameter.

countInPageListWhen(WhenName, LookIn)


This expression little bit same as above expression. 

WhenName - We can use the when condition to evaluate the data in the Current Page of PageList.
                       If the when condition becomes true then count will increase by 1.

LookIn- PageList name in which we want to search.


In acitivity added the expression, If when condition SalesDepartment becomes true then count will increase by 1.




When Condition

This when condition becomes true when current page in page list have department contains Sales.

Lets run the activity and check it.

In the tracer we can see when condition became true for record 9 and 10. So Count should be 2.


Result:

Count is 2.



other expression will see in next post. Ask in comment if you have any doubt😊

Saturday, 14 March 2020

About AddHistory API


About AddHistoryAPI

In this Post, we will see what is AddHistory API activity, Pega provides many API(Built In) activity.

l  We can reuse these activity in many places based on requirement.

APIs is in the path : Configure -> Case Management -> Processed -> APIs





Here we have many built in APIs.

If we see the history of that activity we can understand that this activity will write history to Work Object(Case ID).



A single method used in this activity History-Add , we have to provide Memo(Description) as input parameter.


Demo:

GetCustomerData flow


In Post processing of flow action called AddHistory activity, for that provided a memo(Customer Data has been recieved) as Input






A case has been completed, We can able to see the history in Audit tab.


In History class of customer class we can able to see the history we wrote.


If you click any row a tab wil open , there we can see the xml version by using View XML.




Here we can see more details




Please ask if you have any doubts in comment😊

Thursday, 8 August 2019

Index in Pega (Append, Current, Insert, Last, Prepend)


Index in Pega (Append, Current, Insert, Last, Prepend)


Hi Friends, Today we will see how to use Index in Pega.

To Refer PDN Help click here

There are 5 indexes available.

  1. Append
  2. Current
  3. Insert
  4. Last 
  5. Prepend

Append: (Format: PageList.pxResults(<Append>).PropertyName)

     To add an element to Page List or Value List at the end we will use this index. For Example, We have a page list with 5 Pages if we want to add a new page then we will use this index to append a new page .

In the activity created a new page List named TempList .


Each Page of TempList page list refers to Class "TGB-HRApps-Data-Courses".


Save and executed the activity A Page List is created in Clipboard without any pages in it.


In 2nd Step Property Set added logic to append a new page to page list. In that page ID Property we are setting to value 1.


After Executed the activity a new page is appended in the page list so 1st Page created with values.


Modified Step to Append 3 Pages one after one.

After Executed activity , In Clipboard you can see 3 pages created one after one.


Hope understand about Append Index. Lets see Last Index.

Last: (Format: PageList.pxResults(<LAST>).PropertyName)

If We want to add any property values in Last Page, then we  have to use this index.


After Execute activity you can see Description is added in Last Page(3).


Hope understand about Last Index. Lets see Insert Index.

Insert: (Format: PageList.pxResults(<INSERT>3).PropertyName)

We are use this index to add a page at a particular Index. For example if we want to add a page in 4th Place then we have to give like (<Insert>4)

In the below screenshot we are adding a page in 2nd index , In that page we are setting Description as Chemistry.

After Execute the activity, We can see 2nd page is created with Description Chemistry.



Hope understand about Insert Index. Lets see Prepend Index.


Prepend: (Format: PageList.pxResults(<Prepend>).PropertyName)

Use this index to Add a page in First Index. For example, if you want to add a page in first index of the page list then we have to use this index.

Add a step to Add a page in first index with description Physics


A New Page prepended at 1st index with Description Physics



Hope understand about Prepend Index. Lets see Current Index.

Current: (Format: PageList.pxResults(<Current>).PropertyName)


Current functionality is same as i in for Loop ( for(i=0;i<5;i++) , We can refer Current Loop Page property using this index.

If you see below image we are Copying current loop ID value to Param.ID.
 
So When 1st Loop execute the expression will be TempList.pxResults(1).ID
     When 2nd Loop execute the expression will be TempList.pxResults(2).ID
     When 3rd Loop execute the expression will be TempList.pxResults(3).ID
     etc,



Hope understand about all index. Comment me in case of any doubts friends😊

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) { }
}