Here is a piece of code to prevent duplicate data on a specific field on a page grid. You can of course modify it to check for multiple fields or even the whole row.
| Title | Under | Posted on |
|---|---|---|
| MD5 - SHA checksum of a file. | PeopleSoft Technical | 02/07/2012 - 5:29am |
| nVision Tabular Report through PIA with prompts | PeopleSoft Technical | 02/02/2012 - 10:07pm |
| Can we create an AE to mass update Position - Jobcode data? | PeopleSoft Technical | 01/18/2012 - 3:11am |
| Pay Components on job data can be defaulted and setup based on the rules? | PeopleSoft Functional | 01/05/2012 - 4:58am |
Comments
I would recommend changing the loop counts as we only need to compare 1 to 2,3,4 and 2 to 3,4,5 etc. We don't really need to go back and compare 5 to 1,2,3,4 as this was already handled in previous iterations.
Hence, the outer loop would be:
For &r = 1 To &rs.ActiveRowCount - 1
and the inner loop would be:
For &r1 = &r + 1 To &rs.ActiveRowCount
And you can delete the &r <> &r1 condition as &r will never = &r1.
Chris,
Great observation on your part. Thanks for your feedback, performance wise, your suggestion wins hands down.
Thanks for taking the time to share your remarks with us!
Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog
IN THE CODE THAT YOU HAVE SPECIFIED THE MESSAGE IN THE MESSAGE BOX WILL GET REPEATEDLY DISPLAYED
ie IF ROW1 AND ROW2 ARE SAME AND ROW3 AND ROW4 ARE SAME THEN THE MESSAGE WILL GET DISPLAYED TWICE
INSTEAD TAKE A VARIABLE AND INITIALIZE IT TO ZERO, THEN INCREMENT IT WITHIN THE IF CONDITION.
THEN COME OUT OF THE LOOP AND GIVE ONE MORE IF CONDITION STATING THAT IF THE VARIABLE IS >0 THEN MESSAGE BOX... THIS WAY THE MESSAGE WILL BE DISPLAYED ONCE..
HERE IS THE CODE
Local Row &row1, &row2;
Local number &r, &r1, &I;
&I = 0;
&rs = GetRowset(Scroll.USHR_REC_EX3);
For &r = 1 To &rs.ActiveRowCount - 1
/*Get grid row*/
&row1 = &rs.GetRow(&r);
/*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/
For &r1 = &r + 1 To &rs.ActiveRowCount
&row2 = &rs.GetRow(&r1);
/* if this is a different row, and the field_name value matches then throw an error*/
If &row1.USHR_REC_EX3.LOCATION.Value = &row2.USHR_REC_EX3.LOCATION.Value Then
&I = &I + 1;
End-If;
End-For;
End-For;
If &I > 0 Then
MessageBox(0, "", 0, 0, "Error. Duplicate values are not allowed.");
End-If;
Post new comment