Trying to get info from lockedrecords

I’m trying to get invoice numbers from the serverrecordIDs of locked records. I am stripping the lockedrecordlist to just the record numbers, then trying to replace the severIDs with the invoice numbers of those records. In this case, the list contains 3 serverrecordIDs (each has an invoice number) but only one invoice number is returned; the last one. I tried arrayfilter( , but it gives me the same invoice number three times. I’m doing something wrong, right?

local recordsInUse
lockedrecordlist recordsInUse
if recordsInUse≠ “Ok: 0 records locked”
recordsInUse=arraydelete(recordsInUse,1,1,¶)
recordsInUse=arrayreplacevalue(recordsInUse,recordsInUse,str(InvoiceID),¶)
bigmessage “The following invoices may be locked and may need to be printed later:”+¶+recordsInUse
endif

My first question is, what do locked records have to do with printing? You can certainly print locked records, no problem. Maybe you want to display this list because you think these invoices will change soon? Of course someone could edit any record 1 second after you print, so I’m not sure I understand the point.

In any case, I think arraybuild( is the way to go for this:

local recordsInUse
lockedrecordlist recordsInUse
if recordsInUse≠ “Ok: 0 records locked”
    recordsInUse = arrayrange(recordsInUse,2,-1,cr()) // I like this better than arraydelete(, but whatever
    let lockedInvoiceNumbers = arraybuild(cr(),"",
        {str(InvoiceID)},
        {arraycontains(recordsInUse,str(info("serverrecordid")),cr())})
    bigmessage "Locked invoice numbers:"+cr()+lockedInvoiceNumbers
endif

Where do I send the invoice to? :wink:

I haven’t actually tried this out but couldn’t this shorter version do the same thing?

let lockedInvoiceNumbers=""
arraybuild lockedInvoiceNumbers,cr(),"",InvoiceID,recordislocked
If lockedInvoiceNumbers≠""
    bigmessage “The following invoices may be locked and may need to be printed later:”+¶+ lockedInvoiceNumbers
Endif

Thanks Jim, however, I still have the same issue. Lockedrecordlist returns 3 locked records, but your code also returned only one Invoice number. After running it once, it won’t compile. The error is “missing right parenthesis” on the arraybuild.

Anyway, invoices are printed in batches. They print a batch, then do a bunch of operations afterwards. If a locked record is in the batch, it could screw up the rest of the processes. This is the same database that seems to keep the same records locked for days. If I look in server admin, they show as being locked even though they haven’t been touched.

Gary, your procedure, when run, says “Arrybuild formula error, field or variable [recordislocked] does not exist”

He forgot the parentheses. recordislocked() is a function that returns true if the record is locked.

That’s what happens when you don’t try it before posting. :grimacing:

No, that won’t do the same thing, even if the parentheses are included. The recordislocked() function only tells you if the record is locked by this client. It tells you nothing about whether any other clients have the record locked.

Yes, there was a missing right parenthesis. I have corrected this in the post above.

Exactly.