Tuesday, 28 August 2018

How to save data to database in pega using activity

How to save data to database in pega using activity


In How to create Local Data table in Pega , we saw how to create local data table in pega. Now we can try to insert data to these table by using activity dynamically.

Now assume , our requirement is to get employee Educational Information and store those details to database, for this we have to create one flow. flow contain 1 section in the first section we are getting the educational information and in the first flow action post condition activity we call one activity  there we store those details to database.
How to create flow in pega

Our First Flow action is
How to create flow action in pega
Our section is
How to create section in pega
Now on running the flow our section will display
How to run flow in pega

Now what we have to do is on clicking the submit we have to store the data to database , fot this we have to write one activity in flowaction post condition activity.
How to add post action activity in pega flow action


Flow action activity in pega

Now our New activity will look like this.
activity in pega

In activity first step we have to wrote is"Page-New", For creating new page in clipboard and storing our data .
Page New in pega
After we add the page here , we must give class for this page , because we have to tell pega which class this class is belongs to . So that only we can acess the property in those class using that page.
Pages and class in pega

Then what we have to do is, we have to refer all the properties from clipboard to our activity,


If u confused about clipboard , note this.. After we give values in section and click submit.  Provided values in section will be store in clipboard , so we can access those value from clipboard to activity .

Now I provide some values in our section and click submit.
After click submit , open clipboard and choose our thread(Choose oru case id in clipboard as thread)
Clipboard thread in pega

Normally our data will be there in pyWorkPage.
pyworkpage in pega

So We can access the values from clipboard . Now lets see our activity.
pyworkpage in activity

In second step , I added one property-Set there I copied all the values from clipboard page(pyWorkPage) to Our Page(TempStoreEmpDetail)

U can ask now, where u mentioned pyWorkPage, the answer is .... I left the step page as blank. so dynamically on the activity run time the page will be pyWorkPage so no need to add there pyWorkPage. so I left that blank.

On the Left side of 2nd step property set we have to mention to which property we have to assign those clipboard values.

We have to give column name of table then only we can save the values to table.
property set in pega activity
Now it will refer the Properties in class TGB-HRApps-Data-EmployeeEducationalInfo because our page TempStoreEmpDetail is reffered to this class.

Now the Third step is to save data in TempStoreEmpDetail to database.

Obj Save in pega
Now we are saving all the data in TempStoreEmpDetails page to datbase, so that only I gave Step Page as TempStoreEmpDetails.


Now check whether our flow and activity works or not by giving values in our section and click submit.

I tried its not worked, because we are not provide EmployeeID, that is primary key for that table, we should provide value then only the data will be stored in database.

So we have to add one value in property set 2nd step. I hard Coded with 3 because already there is 2 records there in database.
Hard code values in pega property set

Now try to run.
insert data in to pega local data base

U can see the values are stored in database, but EmployeeHscPercentage is missing, lets solve this issue and Run once more with Employee ID hard Coded with 4.

The problem is I not mapped that values in property set correct.
Now run once again and test.


Now u can see all the values are filled in table.


If u have any doubt ask in comment 😊

8 comments:

  1. Useful post:)
    i have one query..without hard coding the value how to achieve unique increments for employee id property..

    Could you please provide the solution?

    ReplyDelete
  2. Thank you for your comment :) .I will do a separate post for your Query.

    ReplyDelete
  3. I think this post will solve your query, Please refer this post :)
    https://pegalearnings.blogspot.com/2018/11/how-to-insert-records-into-database-in.html

    ReplyDelete
  4. Thank you bharathan:) good work...

    ReplyDelete
  5. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles pega certification

    ReplyDelete
  6. Very Effective one and it is very easy.
    can you please tell me the meaning of STEP PAGE EXACTLY
    That would be helful for me

    ReplyDelete
  7. How to delete few rows from db using OBJ methods
    example : i have 1000 rows in my table and i want delete 10 and these rows exist in steppage and i want delete reocrds which are in step page

    ReplyDelete
  8. This information is really awesome thanks for sharing most valuable information.

    pega testing online training
    pega testing course
    pega testing online course

    ReplyDelete