Expand my Community achievements bar.

Script Checkc DB for Record ID Number

Avatar

Level 9

I am following an example found at PDFScripting.com and ran into a problem. I can get their script to work if my database table has at least one record. But if my database table is brand new with no records, the script fails because it looks for the value in the first record, first column. How do I modify the script to handle when there are no records? I think I need to add an else statement but can't get one to work. (It fails on their example form too)

// Walk Order DB to find highest Order Number
var nMaxID = 0;
// Reset Database to first Record
var oDB = xfa.sourceSet.OrderInfo;
try{
  oDB.first();
}catch(e){
  oDB.open();
  oDB.first();
}
// Walk through all records to find the latest Order ID
while(!oDB.isEOF()){
    if(xfa.record.OrderInfo.OrderID.value > nMaxID)
        nMaxID = Number(xfa.record.OrderInfo.OrderID.value);
    oDB.next();
}
oDB.close();

OrderID.rawValue = nMaxID + 1;

0 Replies