AR_InvoiceHistoryPrinting with BOI

SOLVED

Anyone ever done this?  I have a list of non-consecutive historical invoices I need to export to a specified directory.  I was going to use the 'QuickPrint' property before calling ProcessReport() for each necessary invoice, but I've only ever performed this when dealing with SOs (where there is only one key field).  For Invoice History printing, would I set the 'QuickPrint' property to InvoiceNo + HeaderSeqNo?

  • 0

    When you say "export to a directory"  it sounds as if you need a flat file but then you talk about printing to get hard copies. Which do you need?

  • 0 in reply to BigLouie

    I don't see anywhere in my post where I referenced hard copies.  Maybe I shouldn't have specified a destination for the output/list and just said 'I need to print a historical AR invoice'.

  • 0

    Upon review, while there is an 'AR_InvoiceHistoryQuickPrint_ui' listed in the object reference (and contains a QuickPrint property), when I attempt to create the object using the below:

    oSS.nSetProgram(oSS.nLookupTask("AR_InvoiceHistoryQuickPrint_UI"))

    I get 'Lookup program failed  The task id "0000000000" is not on file'.

    I attempted to go the other route and use the standard 'AR_InvoiceHistoryPrinting_ui'/'AR_InvoicHistoryPrinting_rpt', adapting the code from this post related to SO printing:

    http://sagecity.na.sage.com/support_communities/sage100_erp/f/100/t/41913.aspx

    However when attempting to call the SetKey method for the record selection, I'm receiving 'Report ID Required' (I have printed the 'INVOICE' form code from the Sage UI already):

    if not cbool(oSS.nSetProgram(oSS.nLookupTask("AR_InvoiceHistoryPrinting_UI"))) then
    	MSGBOX CSTR("Set Program: " + oSS.sLastErrorMsg)
    end if
    
    SET oPrint = oScript.NewObject("AR_InvoiceHistoryPrinting_rpt", oSS)
    
    		if not cbool(oPrint.nSelectReportSetting("INVOICE")) then
    			MSGBOX CSTR("Select report setting 'INVOICE': " + oPrint.sLastErrorMsg)
    		end if
    
    		if not cbool(oPrint.nSetKeyValue("ReportSetting$", "INVOICE")) then
    			MSGBOX CSTR("Select report setting 'INVOICE': " + oPrint.sLastErrorMsg)
    		end if
    
    		if not cbool(oPrint.nSetKeyValue("RowKey$", "1")) then
    			MSGBOX CSTR("Set Rowkey: " + oPrint.sLastErrorMsg)
    		end if
    
    		if not cbool(oPrint.nSetKeyValue("ModuleCode$", "A/R")) then
    			MSGBOX CSTR("Set module code: " + oPrint.sLastErrorMsg)
    		end if
    
    		if not cbool(oPrint.nSetKey()) then
    			MSGBOX CSTR("Setkey: " + oPrint.sLastErrorMsg)
    		end if

  • 0 in reply to Justin K

    When you go into invoice history printing, you have to pick "Accounts Receivable" or "Sales Order" first, is it referring to that?

  • 0 in reply to Sage100User

    I noticed that as well, but I don't believe that's what its referring to.  The reason I say that is because I first got the message 'Module Code Required' when calling SetKey().  That prompted me to add the 'ModuleCode' SetKeyValue line (which suppressed the module code error, but moved me on to the 'report ID' error).

  • +1 in reply to Justin K
    verified answer

    You should be able to use the QuickPrint property of the AR_InvoiceHistoryPrinting_rpt class object however the value you need to set is vastly different compared to sales orders.

    Here's a two screenshots of the value returned, the first is for an AR invoice, the second is for an SO invoice.

    The underscores are actually the null character (ASCII # 0) but i replaced them with underscores so i could see the full string in the msgbox window. 

    It appears the value is comprised of the following.

    1. invoice's originating module (i'm unsure if this is only used to determine form code selection, i.e. A/R vs S/O or if is actually used when selecting the invoice number by comparing ModuleCode of the record in history, if the former, you could always use the AR_InvoiceHistoryInquiry_svc to locate the record you are after and return the key padded using the kCustomer index and GetKeyPadded, then just specify the module of the form code you want to use followed by the padded key).
    2. customer AR division number.
    3. customer number padded on the right with the null character to max length of field.
    4. invoice number padded on the right with the null character to max length of field (padding is only required if the invoice number's length is less than the max length, not typically required if using the next available number).
    5. invoice header sequence number.

    If you don't know the header sequence number, you could use the AR_InvoiceHistoryInquiry_svc class to get get all the info you need or just use the AR_InvoiceHistoryPrinting_rpt class' record selection methods to select by invoice number.

    Regardless of whether you do or do not use the quick print method, you also need to make sure you call the SetModuleToPrint method and pass it either "S/O" or "A/R" depending on the invoice form you want to use, it is what this dropbox does in the UI.

    As for creating record selections with a report object, the following should help.  You can use a comma separated list of invoices when setting the value for the invoice number with the operand being "Equal to" so you only have to process the report once, however, i believe doing so would export them all to a single file so you may be better off either using the QuickPrint property or just specify one invoice at a time.  The following script example is from an external script so the methods are prefixed with the returned data type, remove these if using on a button script (internal script).

    ' Set the selection criteria.
    ' If I'm not mistaken, KeyReference should be set for multi-part keys and should be something like this, "<APDivisionNo$+VendorNo$>". The arrows must be included and wrap the fields that make up the multi-part key.
    ' Tag must include the table name and column name like this, "Table=CI_Item;Column=ItemCode$;".
    ' Increment nRowKey for each row used in the selection.
    nRowKey = 0 
    
    Row 1
    	nRowKey = nRowKey + 1
    	oReport_Rpt.nSetKeyValue "ModuleCode$", oSession.sModuleCode 
    	oReport_Rpt.nSetKeyValue "CompanyKey$", oSession.sCompanyKey 
    	oReport_Rpt.nSetKeyValue "ReportID$", oReport_Rpt.sReportID 
    	oReport_Rpt.nSetKeyValue "ReportSetting$", UCase(sReportSetting)
    	oReport_Rpt.nSetKeyValue "RowKey$", Right("00000" & CStr(nRowKey), 5) 
    	oReport_Rpt.nSetKey 
    	oReport_Rpt.nSetValue "SelectField$", "Item Code" 
    	oReport_Rpt.nSetValue "SelectFieldValue$", "Item Code" 
    	oReport_Rpt.nSetValue "KeyReference$", ""
    	oReport_Rpt.nSetValue "Tag$", "Table=CI_Item;Column=ItemCode$;"
    	oReport_Rpt.nSetValue "Operand$", "=" 
    	oReport_Rpt.nSetValue "Value1$", "2551-3-50" 
    	oReport_Rpt.nSetValue "Value2$", "" 
    	oReport_Rpt.nWrite 
    	
    Row 2
    	nRowKey = nRowKey + 1
    	oReport_Rpt.nSetKeyValue "ModuleCode$", oSession.sModuleCode 
    	oReport_Rpt.nSetKeyValue "CompanyKey$", oSession.sCompanyKey 
    	oReport_Rpt.nSetKeyValue "ReportID$", oReport_Rpt.sReportID 
    	oReport_Rpt.nSetKeyValue "ReportSetting$", UCase(sReportSetting)
    	oReport_Rpt.nSetKeyValue "RowKey$", Right("00000" & CStr(nRowKey), 5) 
    	oReport_Rpt.nSetKey 
    	oReport_Rpt.nSetValue "SelectField$", "Product Line" 
    	oReport_Rpt.nSetValue "SelectFieldValue$", "Product Line" 
    	oReport_Rpt.nSetValue "KeyReference$", "" 
    	oReport_Rpt.nSetValue "Tag$", "Table=CI_Item;Column=ProductLine$;"
    	oReport_Rpt.nSetValue "Operand$", "=" 
    	oReport_Rpt.nSetValue "Value1$", "FD&A" 
    	oReport_Rpt.nSetValue "Value2$", "" 
    	oReport_Rpt.nWrite 

    Finally, watch out for report options, like the stuff that appears above the selection grid.  If you need to override these, adapt the following.  The following script example is from an external script so the methods are prefixed with the returned data type, remove these if using on a button script (internal script).

    ' Get the current report options.
    	sReportOptions = "" : oReport_Rpt.nGetOptions sReportOptions
    
    ' Replace the report option specified in the second argument with the value specified in the third argument.
    	oReport_Rpt.nReplaceDefault sReportOptions, "CB_UNPAIDINVSONLY$", "Y"
    	oReport_Rpt.nReplaceDefault sReportOptions, "DB_PRINTCOMMENT$", "F"
    	oReport_Rpt.nReplaceDefault sReportOptions, "DB_PAPERLESSOFFICEOUTPUT$", "1"
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_INVMSG1$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_HISTMSG1$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_INVMSG2$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_HISTMSG2$", ""
    	
    ' Set the modified report options.
    	oReport_Rpt.nSetOptions sReportOptions

  • 0 in reply to David Speck

    Wow thanks so much for all the details David.  Let me review/give it a try and I'll report back with the results!

  • +1 in reply to David Speck
    verified answer

    So unfortunately I'm running into an error when calling the ProcessReport Method (passing it the argument 'PREVIEW'.  Below is my script in its entirety (attempting to print a historical invoice included in the ABC demo data):

    EDIT: Not sure why, but Sage City is not letting me post the code of my script (either in 'Code' or plain text).  Will try to get it posted asap.  

  • 0

    Dim oScript, oss, retval, oPrint


    Set oScript = CreateObject ("ProvideX.Script")
    oScript.Init "C:\Sage\Sage 100 Standard 2020\MAS90\Home"
    Set oSS = oScript.NewObject("SY_SESSION")

    if not cbool(oSS.nLogon()) then
    MSGBOX CSTR("Logon: " + oSS.sLastErrorMsg)
    end if


    if not cbooL(oSS.nSetCompany("ABC")) then
    MSGBOX CSTR("Set Company: " + oSS.sLastErrorMsg)
    end if

    if not cbool(oSS.nSetModule("A/R")) then
    MSGBOX CSTR("Set Module: " + oSS.sLastErrorMsg)
    end if

    if not cbool(oSS.nSetDate("A/R", Year(Date) & Right("00" & Month(Date), 2) & Right("00" & Day(Date), 2))) then
    MSGBOX CSTR("Set Date: " + oSS.sLastErrorMsg)
    end if

    if not cbool(oSS.nSetProgram(oSS.nLookupTask("AR_InvoiceHistoryPrinting_UI"))) then
    MSGBOX CSTR("Set Program: " + oSS.sLastErrorMsg)
    end if

    SET oPrint = oScript.NewObject("AR_InvoiceHistoryPrinting_rpt", oSS)


    if not cbool(oPrint.nSelectReportSetting("STANDARD")) then
    MSGBOX CSTR("Select report setting 'INVOICE': " + oPrint.sLastErrorMsg)
    end if

    oPrint.sQuickPrint = "S/O01SHEPARD" + chr(0) + chr(0) + chr(0)+ chr(0)+ chr(0)+ chr(0)+ chr(0) + chr(0)+ chr(0)+ chr(0)+ chr(0)+ chr(0)+ chr(0) + "0100045000000"

    if not cbool(oPrint.nProcessReport("PREVIEW")) then <-----Throws error shown below
    MSGBOX CSTR("Process report: " + oPrint.sLastErrorMsg)
    end if


    oPrint.DropObject
    SET oPrint = Nothing
    oSS.nCleanup()
    oSS.DropObject()
    Set oSS = Nothing
    Set oScript = Nothing

  • 0 in reply to Justin K

    I was able to get this to work. This is what I did. I put my customer number and invoice number into variables. I hard coded the division as "00" since we don't use divisions.

    Note I can't seem to post code snippets either apparently!