Update GL_ActiveBatchComment Script Help

SOLVED

Hello everyone, apologies if this has been asked before but I wasn't able to find something quite like this.

We're on SAGE 100c 2018 v6.00.6.0

I have a script I want to run on a table to update the batch comments based on a few conditions.  I have narrowed my problem down to the section in my script around GL_ActiveBatchComment.  I looked in SAGE and noticed that this table does not have a Business Object associated with it.



Here is my script for reference

receiptType="":vendorNum="":batchNum="":approval="":batchComment="":firstBatchNum="":myReceiptType="":myVendorNum="":myBatchNum="":myApproval=""
:oCompany=""
Dim readyToWrite

batchComment="EDI Batch - All Receivers Approved"

oCompany = oSession.CompanyCode
if oCompany = "TST" then
result = oBusObj.GetValue("ReceiptType$",receiptType)
result = oBusObj.GetValue("VendorNo$",vendorNum)
result = oBusObj.GetValue("BatchNo$",batchNum)
result = oBusObj.GetValue("UDF_RECEIVER_APPROVED$",approval)

if (receiptType="G") and (vendorNum="MOORE01") and (batchNum <> "") and (approval="Y") then

Set oPO_ReceiptHeader = oSession.AsObject(oSession.GetObject("PO_Receipt_bus"))
oPO_ReceiptHeader.MoveFirst()
retVal = oPO_ReceiptHeader.GetValue("ReceiptType$",myReceiptType)
retVal = oPO_ReceiptHeader.GetValue("VendorNo$",myVendorNum)
retVal = oPO_ReceiptHeader.GetValue("BatchNo$",myBatchNum)
retVal = oPO_ReceiptHeader.GetValue("UDF_RECEIVER_APPROVED$",myApproval)

Do While oPO_ReceiptHeader.EOF<>1
if (receiptType = myReceiptType) and (vendorNum = myVendorNum) and (batchNum = myBatchNum) then
if myApproval = "Y" then

readyToWrite = true

else
readyToWrite = false
Exit Do

End if

End if

oPO_ReceiptHeader.MoveNext()
retVal = oPO_ReceiptHeader.GetValue("ReceiptType$",myReceiptType)
retVal = oPO_ReceiptHeader.GetValue("VendorNo$",myVendorNum)
retVal = oPO_ReceiptHeader.GetValue("BatchNo$",myBatchNum)
retVal = oPO_ReceiptHeader.GetValue("UDF_RECEIVER_APPROVED$",myApproval)

Loop


retVal = oSession.AsObject(oSession.UI).Messagebox("right before readyToWrite = true check")
if (readyToWrite = true) then
retVal = oSession.AsObject(oSession.UI).Messagebox("inside the readyToWrite = true check")

retVal = oSession.AsObject(oSession.UI).Messagebox("BEFORE ACTIVE BATCH OPEN")
Set oGL_CompanyActiveBatch = oSession.AsObject(oSession.GetObject("GL_CompanyActiveBatch_bus"))
retVal = oSession.AsObject(oSession.UI).Messagebox("right AFTER opening active batch!")

'Set comment to whatever is in the field, if anything
Dim comment
retVal = oSession.AsObject(oSession.UI).Messagebox("after comment DIM")
result = oGL_CompanyActiveBatch.GetValue("Comment$", comment)
retVal = oSession.AsObject(oSession.UI).Messagebox("after comment get value")
'If the comment contains a batch comment already, do nothing else append batch comment
if (LEFT(comment,34) = "EDI Batch - All Receivers Approved") then
retVal = oSession.AsObject(oSession.UI).Messagebox("inside batch comment check")
else
comment = "EDI Batch - All Receivers Approved" + " " + comment
retVal = oSession.AsObject(oSession.UI).Messagebox("after batch comment has been set")
'Set value and write
result = oGL_CompanyActiveBatch.SetValue("Comment$",comment)
retVal = oSession.AsObject(oSession.UI).Messagebox("Active batch comment set")
result = oGL_CompanyActiveBatch.Write()
retVal = oSession.AsObject(oSession.UI).Messagebox("ACTIVE BATCH HAS BEEN WRITTEN")
end if
else
end if
Else
end if
end if

If it is not possible to edit comments in this table outside of SAGE, is there a different way that I might update the batch comments?

Thank you in advance for any help!

  • +1
    verified answer

    I'm assuming you have your script attached to PO_ReceiptHeader.

    In you script, you should be able to use oBusObj.GetValue "coBatch", nBatch and then check if nBatch is greater than 0, if it is, pass it to oSession.AsObject() so you can can set the object handle into something like oBatch. Then check if oBatch is on the correct batch record and if it is, you should be able to use SetValue on the Comment$ field. I do not if for sure if you need to use oBatch.Write as i haven't tested this myself (besides verifying the coBatch should contain the batch handle) so you will need to do a little testing, if you do end up needing the Write method, you might also have to put the record back in an edit state so use GetKey to first store the batch record key into a variable and then after the Write, passed the stored key to the SetKey method.