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)
-
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.

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.

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?
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