Discussion
Virtusa
LK
Last activity: 29 Oct 2015 5:16 EDT
Increment the Primary Key of a Data Table
I need to set the Primary Key of a Data Table as 1,2,3,4... . The latest row's Primary Key should be "Last Row's Primary Key + 1". How can I achieve this?
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Coforge DPA
GB
Hi ,
You can foloow below steps ;
1)Do an OBj-Browse on the table
2)Set MAXRecords as 1
3)Put the field you want in "Select" field
4) Condition as "Value Only"
5) Sort as "Descending"
This way you get the highest value for the key and then you can add 1 to it in next step .
Hope this helps.
-
Reco D
Virtusa
LK
I created and called the activity. But nothing is shown in the clipboard.
Coforge DPA
GB
Hello ,
I have tried as below screenshot and it worked
Coforge DPA
GB
Coforge DPA
GB
Can you Uncheck the "Select" and try .
Virtusa
LK
Unchecked the "Select" and still not getting anything.
PEG
IN
Did you remove the RowKey value also?
NIIT Technologies Limited
AU
I think we cannot uncheck 'Select' as Obj-Browse will not return any data in that case, not even the max value we want.
- Please check the 'Select' field for PrescriptionID,
- Remove step page
- Uncheck 'Get row key'
- Uncheck 'Light weight List'
Also, how Obj-Browse will understand that it has to sort in descending order?
Give label to the condition and mention the same in logic field.
Coforge DPA
GB
Coforge DPA
GB
Just keep the step as in above screenshot . It should work.
PEG
IN
Please try as shown in above screen shot. It should work. I tried in my local and worked for me.
INCESSANT TECHNOLOGIES
IN
Hi,
I am facing an issue with this approach. When I do sort as descending, number "9" is considered as greater than "10". Since the primary key "ID" of my table is Varchar. Is there any way to get rid of this issue?
Infosys
AU
Hi Sathya,
Did you try using "Pega-RULES:defaultCompareNumbers" as the override sort function on the property rule form? I think this will solve the issue.
Murali...
Pegasystems Inc.
IN
Please follow these steps:
1) Create RD. For column source, use function [Text Value] converted to an Integer value & add your column name. Select sort type as Highest to lowest.
2) Update your activity to use call Rule-Obj-Report-Definition.pxRetrieveReportData method instead of Obj-Browse.
pyReportName <<report name created in step1>>
pyReportCalss <<Applies to class of report created in step1>>
pyPageName <<Enter any page list of type Code-Pega-List>>
3) Now the result is stored in <<pyPageName>>.pxResults(1).<<column name used @ stpe 1>>.
Here, <<pyPageName>>.pxResults will be of type pyReportClass.
4) An incremented value can be obtained as @String.toInt(<<pyPageName>>.pxResults(1).<<column name used @ stpe 1>>)+1