Printing From Shipping Data Entry

SOLVED

Sage 100 ERP 5.00.8.0

We are adding a button to our Shipping Data Entry that calls for a print of an invoice based on a Sales Order Number. I am consistently getting the following two errors:

1)  "The S/O0000000022SO_INVOICEPRINTING_UI         STANDARD            00001 is invalid." (If I use Quick Print)

2) "Data is not selected for report printing." (Regardless of Quick Print vs. Standard; Same with new and existing shipments; Does not matter if I PRINT or PREVIEW)

This script is being run on the server:

retVal = 0
OrderNo = ""

retVal = oBusObj.GetValue("SalesOrderNo", OrderNo)
retVal = oBusObj.Write()

retVal = oSession.SetModule("S/O")
retVal = oSession.SetDate("S/O", MAS_SCR_DTE)

Dim soPRINT
SET soPRINT = oSession.AsObject(oSession.GetObject("SO_InvoicePrinting_rpt"))

' Select the Template record.
retVal = soPrint.SetPartialRecord("Plain", oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") )
If Mid(OrderNo, 1, 1) = "R" Then
soPRINT.SelectReportSetting("RDD")
soPRINT.SetKeyValue "ReportSetting$", "RDD"
Else
soPRINT.SelectReportSetting("STANDARD")
soPRINT.SetKeyValue "ReportSetting$", "STANDARD"
End If

retVal = soPRINT.SetKeyValue("ModuleCode$", "S/O")
retVal = soPRINT.SetKeyValue("CompanyKey$", oSession.CompanyKey)

soPRINT.SetKeyValue "RowKey$", "1"
soPRINT.SetKey()
if retVal = 0 then
retVal = oSession.AsObject(oSession.UI).MessageBox("", soPRINT.LastErrorMsg & "1")
end if

' Set Selection criteria
retVal = soPRINT.SetValue("SelectField$", "Order Number")
retVal = soPRINT.SetValue("SelectFieldValue$", "Order Number")
retVal = soPRINT.SetValue("Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=SALESORDERNO$")
retVal = soPRINT.SetValue("Operand$", "=")
retVal = soPRINT.SetValue("Value1$", OrderNo)
retVal = soPRINT.QuickPrint = OrderNo 'Error #1 Here
'retVal = soPRINT.Write()
if retVal = 0 then
retVal = oSession.AsObject(oSession.UI).MessageBox("Write", soPRINT.LastErrorMsg)
end if

'retVal = soPRINT.ProcessReport("PRINT")
retVal = soPRINT.ProcessReport("PREVIEW") ' Error #2 Here
if retVal = 0 then
retVal = oSession.AsObject(oSession.UI).MessageBox("Print", soPRINT.LastErrorMsg)
end if

I have been through the BOI courses - though it has been a while, and I have looked through the examples, but I cannot find anything remotely like what I am trying to do. I am certain I have some extraneous and/or missing information, but I am not sure what. Any thoughts?

Parents
  • 0

    My gut reaction regarding #2  is that if you are clicking the button while sitting in shipping data entry, the invoice records have not been created yet.  SO_InvoicePrinting has to have an invoice created already,  it can't print it from data in the sales order files,  must be in the sales order invoice files.

    Have you verified via DFDM that data exists in SO_Invoice_Header?

    Does that make sense?

  • 0 in reply to TomTarget

    That does make sense (and that is where the button is) - and that was my first thought as well, but I don't think it could be the cause with what I have currently for two reasons:

    1) For brand new shipments, the invoice is created through oBusObj.Write(). I do not know if this is the best way, but it is working, and the invoices are written before the soPRINT object is even created.

    2) I get the same error for existing invoices/shipments that I verified before testing.

    Given these facts I think there is something wrong with my code other than that. For what its worth, I had it working with new shipments/invoices earlier, but it broke when I tried to make it work for existing ones as well, and I am not quite sure how to replicate my earlier setup.

  • 0 in reply to TomTarget

    Sounds good to me.

  • 0 in reply to TomTarget

    Well,  I succeeded in actually printing the invoice by using the invoice number (I did get the form warning).   However,  I then got an error message indicating that the record is in use by another task which I think makes sense.

    Shipping data entry has a lock on that invoice record.   When the invoice printing is done via the script,  it is trying to set the flag indicating that the invoice has been printed.   Since the record is locked it cannot update it,  hence the record in use message.

    OK,  I'm going to follow my tag line at this point.   Since shipping data entry has the ability to print the invoice already,   why do you need to add this button for printing the invoice?

  • 0 in reply to TomTarget

    We want custom logic to set the Report Setting field automatically - to either Standard or RDD depending on the first character of the order number. As I understand it, my shipping department wants it to replace the standard Quick Print button.

  • 0 in reply to vbnet3d

    That makes  sense to me.

    I suspect the file lock might be the ultimate problem even if you can resolve the rest of it.

    Seems like in other projects that I have done,  selecting Quick Print has two effects.  #1  it saves your data entry (and I assume releases the lock on the record)  and #2  actually prints the document.

    Based on that my guess is that you would have to have your new button do the equivalent of hitting the Accept button   (retval=oScript.InvokeButton("button_name")?),   followed by the actual printing (your script).

    Sorry that I've brought up a third potential problem to solve.

    P.S.   I discovered that I don't quite have the invoice selection nailed down.  It's actually doing an ALL invoices.

  • 0 in reply to TomTarget

    ... AND... I didn't get the record is in use message for the invoice that I did not currently have open in shipping data entry.

  • 0 in reply to TomTarget

    I think I just got everything but setting the form.   Confirming.

  • 0 in reply to TomTarget

    OK.  Just as you had mentioned,  it worked once and then you got no data selected for printing on the next try.    That appears to be because the flag has been sent that the invoice has already been printed.  Flag is there to keep from inadvertently printing it multiple times.   So that is working as expected.   Just need to figure out how to set the print flag for "Print invoices previously printed"

  • 0 in reply to TomTarget
    verified answer

    This seems to work with the exception of setting the report format and print invoices previously printed.   Added comments so you could see where I changed things.

    retVal = 0

    OrderNo = SO_Shipping_bus_InvoiceNo   'this is being passed from the window to the script

    retval = oScript.InvokeButton("BT_ACCEPT")    'THESE TWO LINES HIT THE ACCEPT BUTTON AND UNLOCK THE RECORD

    retval = oUIObj.HandleScriptUI()

    'retVal = oBusObj.GetValue("SalesOrderNo", OrderNo)    disabled these two lines in favor of the above method of get the invoice number

    'retVal = oBusObj.Write()

    retVal = oSession.SetModule("S/O")

    retVal = oSession.SetDate("S/O", MAS_SCR_DTE)

    Dim soPRINT

    SET soPRINT = oSession.AsObject(oSession.GetObject("SO_InvoicePrinting_rpt"))

    ' Select the Template record.

    retVal = soPrint.SetPartialRecord("Plain", oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") )

    If Mid(OrderNo, 1, 1) = "R" Then

    soPRINT.SelectReportSetting("RDD")

    soPRINT.SetKeyValue "ReportSetting$", "RDD"

    Else

    soPRINT.SelectReportSetting("STANDARD")

    soPRINT.SetKeyValue "ReportSetting$", "STANDARD"

    End If

    retVal = soPRINT.SetKeyValue("ModuleCode$", "S/O")

    retVal = soPRINT.SetKeyValue("CompanyKey$", oSession.CompanyKey)

    soPRINT.SetKeyValue "RowKey$", "1"

    soPRINT.SetKey()

    if retVal = 0 then

    retVal = oSession.AsObject(oSession.UI).MessageBox("", soPRINT.LastErrorMsg & "1")

    end if

    ' Set Selection criteria

    retVal = soPRINT.SetValue("SelectField$", "Shipping/Invoice Number")     'modified the selection criteria

    retVal = soPRINT.SetValue("SelectFieldValue$", "Shipping/Invoice Number")  'modified the selection criteria

    retVal = soPRINT.SetValue("Tag$", "TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$")  'modified the selection criteria

    retVal = soPRINT.SetValue("Operand$", "=")

    retVal = soPRINT.SetValue("Value1$", OrderNo)

    retVal = soPRINT.QuickPrint = OrderNo 'Error #1 Here

    'retVal = soPRINT.Write()

    if retVal = 0 then

    retVal = oSession.AsObject(oSession.UI).MessageBox("Write", soPRINT.LastErrorMsg)

    end if

    'retVal = soPRINT.ProcessReport("PRINT")

    retVal = soPRINT.ProcessReport("PREVIEW") ' Error #2 Here

    if retVal = 0 then

    retVal = oSession.AsObject(oSession.UI).MessageBox("Print", soPRINT.LastErrorMsg)

    end if

  • 0 in reply to TomTarget

    Figured out where your sample code came from.   It had this comment before the formatting selection.

    ' Select the report setting for the form

           ' Note: Template record for User/Form must already exist, E.g. The form

           ' printing task has to be run in MAS 90 up to the point of selecting a

           ' form template (Plain, Preprinted, Marbled, Etc.)

    Unfortunately,  looks like we've got everything except your key reason for doing this, because even with this little tidbit,  I can't get it to change the form setting.

  • 0 in reply to TomTarget

    That clarity is very helpful. I think we might be able to live with this solution. I should clarify that it is not the 'form' setting that I was trying to change - I think my explanation was not clear. It is the 'Report Setting', which does seem to be setting correctly. Thank you so much for your input!

Reply
  • 0 in reply to TomTarget

    That clarity is very helpful. I think we might be able to live with this solution. I should clarify that it is not the 'form' setting that I was trying to change - I think my explanation was not clear. It is the 'Report Setting', which does seem to be setting correctly. Thank you so much for your input!

Children