Need help with UDS and GetChildObject method to access "AR_PaymentType_Bus"

SOLVED

Here's my situation:

The UDS is on the Pre-Totals event of S/O invoice header and I am trying to access a field in the "AR_PaymentType" table. I would appreciate if anyone could see by blunder in any of the 4 methods I describe here.

Methods I've tried:

  1. The oBusObj.GetDataSources() method indicates that "PaymentType" is a child of the invoice header, but the statement:
    Set oPaymentType = oBusObj.AsObject(oBusObj.GetChildHandle("PaymentType"))
    returns an error "Wrong number of arguments or invalid property assignment"
  2. If I separate the combined statements above into two:
    oPaymentType = oBusObj.GetChildHandle("PaymentType")
    retVal = oScript.DebugPrint(SCRIPT_ID & "oPaymentType = " & oPaymentType)
    	
    Set oPaymentType = oBusObj.AsObject(oPaymentType)
    retVal = oScript.DebugPrint(SCRIPT_ID & "oPaymentType = " & oPaymentType)
    the GetChildHandle method above returns oPaymentType = 100078 (which matches the variable "coPaymentTypeChild" value in a debug dump),
    but the Set statement gets the same error as in #1 above: "Wrong number of arguments or invalid property assignment".
  3. I tried using the existing variable "coPaymentTypeChild" directly in this statement:
    oPaymentObj = 0
    retVal = oBusObj.GetValue("coPaymentTypeChild", oPaymentObj)
    retVal = oScript.DebugPrint(SCRIPT_ID & "oPaymentObj = " & oPaymentObj)
    if oPaymentObj <> 0 Then
    		Set oPaymentObj = oBusObj.AsObject(oPaymentObj)
    the DebugPrint show oPaymentObj as 100078 (again, matching the variable "coPaymentTypeChild" value in a debug dump),
    but the Set statement gets an error "Invalid/Unknown property name, Wrong number of arguments or invalid property assignment (err/ret=2/0)"
  4. My final attempt is to access the "AR_PaymentType_Bus" table directly and "SetKey" to the specific PaymentType with both of the following statements (separately):
    Set oPaymentObj = oBusObj.AsObject(oBusObj.GetObject("AR_PaymentType_bus"))
    Set oPaymentObj = oSession.AsObject(oSession.GetObject("AR_PaymentType_bus"))
    Both these statements get the error message "Invalid/unknown property name, Wrong number of arguments or invalid property assignment (err/ret=2/0)"
     
  • 0

    Do you think it is case sensative?  In the file layout it is shown as  PAYMENTTYPE

  • +1
    verified answer

    I think the PaymentType child goes to the invoice's payment entry, which probably won't exist unless it's a CC transaction...

    If you just want to look up a value in AR_PaymentType, why not flow a UDF into the invoice header (instead of doing a lookup)?

  • 0 in reply to Kevin M

    Thanks for the responses. My test invoice is a CC transaction with a filled Payment tab, but I expected the object to return zero if it weren't and to not generate an error. Thanks for the idea to flow it. I'll try that, as can been seen, I have a hard time giving up.

  • 0
    SUGGESTED

    I was never able to get writing to the Sales Order Payment object to work for credit cards. What I did instead, is write the credit card to the customer, then reference the Credit Card ID on the sales order. This actually worked.

    Here are some code snippets:

    r = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))
    Set o = oScript.NewObject("SO_SalesOrder_bus", oSS)
    r = o.nSetKeyValue("SalesOrderNo$", SalesOrderNo)
    r = o.nSetKey()

    ...

    Set oPmt = o.oPaymentObj
    
    r = oPmt.oARCreditCard.nAddNewCreditCard(PaymentType, ccNumber, expirationYear, expirationMonth, guid)
    
    Set oCustCreditCard = oScript.NewObject("AR_CustomerCreditCard_bus", oSS)
    r = oCustCreditCard.nSetKeyValue("ARDivisionNo$", "00")
    r = oCustCreditCard.nSetKeyValue("CustomerNo$", CustomerNo)
    r = oCustCreditCard.nSetKeyValue("CreditCardGUID$", guid)
    r = oCustCreditCard.nSetKey()
    r = oCustCreditCard.nSetValue("PaymentType$", PaymentType)
    r = oCustCreditCard.nSetValue("CreditCardID$", CreditCardID)
    r = oCustCreditCard.nSetValue("ExpirationDateYear$", expirationYear)
    r = oCustCreditCard.nSetValue("ExpirationDateMonth$", expirationMonth)
    
    r = oCustCreditCard.nWrite()
    Set oCustCreditCard = Nothing
    
    r = oPmt.nAddDeposit()
    r = oPmt.nSetValue("CreditCardID$", CreditCardID)
    
    r = oPmt.nWrite()
    
    r = o.nWrite()

  • 0 in reply to Sage100User

    Thanks for that helpful code snippet, but my need was to read a field in the AR_PaymentType table. I ended up using 's suggestion of having it flow to SO_InvoiceHeader.

  • +1
    verified answer

    Is this on a stock system or are there other enhancements?

    I just threw this test script together and it worked on my stock 2018 system.

  • 0 in reply to Kevin M

    In SO Invoice Date Entry, the coPaymentTypeChild handle is the AR_PaymentType_Svc class and its table is AR_PaymentType.

  • 0 in reply to David Speck

     This worked perfectly (minus the MoveFirst as it was already positioned correctly). Thank you AGAIN!!!  I just want to know why didn't the 1st method (as documented in multiple scripting resources including Steve M's) work?

    Hey  is there an award for the most helpful person in this forum? David deserves it!!!

  • 0 in reply to connex

    I stopped using statements that combined AsObject and GetObject, NewObject, or GetChildHandle because i don't like to have to use On Error Resume Next unless absolutely required to. Imho, it is much better to get the numeric value returned by the last three into its own variable, hence the "n" prefix, test it for not being equal to zero and if not, then set it as an object handle with a "o" prefix using AsObject. 

    Although the MoveFirst shouldn't be needed as i was just making sure that it really was going to the payment type table and not some other table. However, you may or may not need to include a [ReadAdditional "PaymentType"] before getting the child object or before getting your values from the child object. Have seen a few cases where the child object wasn't on the record i was expecting and ReadAdditional resolves that. If you don't pass it any arguments, it will read all child data sources so you can potentially save on resource overhead by just passing "PaymentType" to it so it will only read that child data source.

  • 0 in reply to connex

    - I agree there are a number of incredibly helpful individuals that continuously contribute on these forums and you should all be commended.  among two I know in particular, and you usually have the question answered before I can even read it. :)   Guess I'm getting obsolete Slight smile

    Thanks to everyone that makes this a real community!!!