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.
Our First Flow action is
Our section is
Now on running the flow our section will display
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.
Now our New activity will look like this.
In activity first step we have to wrote is"Page-New", For creating new page in clipboard and storing our data .
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.
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)
Normally our data will be there in pyWorkPage.
So We can access the values from clipboard . Now lets see our 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.
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.
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.
Now try to run.
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 😊
Our section is
Now on running the flow our section will display
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.
Now our New activity will look like this.
In activity first step we have to wrote is"Page-New", For creating new page in clipboard and storing our data .
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)
Normally our data will be there in pyWorkPage.
So We can access the values from clipboard . Now lets see our 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.
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.
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.
Now try to run.
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 😊
Useful post:)
ReplyDeletei have one query..without hard coding the value how to achieve unique increments for employee id property..
Could you please provide the solution?
Thank you for your comment :) .I will do a separate post for your Query.
ReplyDeleteI think this post will solve your query, Please refer this post :)
ReplyDeletehttps://pegalearnings.blogspot.com/2018/11/how-to-insert-records-into-database-in.html
Thank you bharathan:) good work...
ReplyDeleteEnjoyed 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
ReplyDeleteVery Effective one and it is very easy.
ReplyDeletecan you please tell me the meaning of STEP PAGE EXACTLY
That would be helful for me
How to delete few rows from db using OBJ methods
ReplyDeleteexample : 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
This information is really awesome thanks for sharing most valuable information.
ReplyDeletepega testing online training
pega testing course
pega testing online course