That will be tricky since the possibility exists that more than one check was used to pay the document.
APDoc <-->>APAdjust
In other words, APDoc has a one-to-many relationship with APAdjust.
It might be simpler to run a nightly (more frequent?) query via SQL Agent to populate the minimum check number from APAdjust into an APDoc.User[X] field, and then display the APDoc.user[X] field on the 03.250 AP Document Maintenance screen (display only of course!).
Code to look at the relationship of the APDoc record to the APAdjust record might look like this:
select apdoc.cpnyid, apdoc.perpost,apadjust.perappl, apdoc.vendid, apdoc.doctype,
apdoc.refnbr as VoucherNbr, apadjust.adjgrefnbr as ChkNbr,
apdoc.origdocamt as DocAmt, apadjust.adjamt as ChkAmt, apadjust.AdjDiscAmt as TermsDiscount
from apdoc (nolock)
inner join apadjust (nolock) on apdoc.refnbr = apadjust.AdjdRefNbr
and apdoc.doctype = apadjust.adjddoctype and adjgdoctype in ('CK','HC','ZC')
--be sure to eliminate vouchers cleared via debit adjustments
where apdoc.perpost in (select pernbr from apsetup)
--Only select current period so query run faster
Code to look at the minimum check number associated with an APDoc voucher would look like this:
select apdoc.cpnyid, apdoc.doctype, apdoc.refnbr as VoucherNbr, min(apadjust.adjgrefnbr) as ChkNbr
from apdoc (nolock)
inner join apadjust (nolock) on apdoc.refnbr = apadjust.AdjdRefNbr
and apdoc.doctype = apadjust.adjddoctype and adjgdoctype in ('CK','HC','ZC')
--be sure to eliminate vouchers cleared via debit adjustments
where apdoc.perpost in (select pernbr from apsetup)
group by apdoc.cpnyid, apdoc.doctype, apdoc.refnbr
Hope this helps.
Gail J-N