error on SetKey method

SOLVED

Getting an error when SetKey method used, saying vendor code is not numeric. Won't insert record into invoice data entry.

  • 0
    SUGGESTED

    In most cases, "[field] is not numeric" is a false positive. You should not just rely on checking the LastErrorMsg property of the object performing the methods. 

    If you have a method that is not performing as expected, check its returned value.

    This is most commonly done like this.


    nRetVal = 0 : nRetVal = oBusObj.SetKey("KeyValue")

    If nRetVal = 0 Then

    oSession.AsObject(oSession.UI).MessageBox "", "SetKey failed." & vbCrLf & nRetVal & vbCrLf & oBusObj.LastErrorNum & vbCrLf & oBusObj.LastErrorMsg

    End If


    It is good to be familiar with the values that the various methods will return. In the case of SetKey, it will return the following.

    • 0 if it failed
    • 1 if the record already exists
    • 2 if the record is new

    Other methods like SetValue can return a -1 if a warning is triggered.

    Assuming you are trying to create an AP Invoice Entry record, that task's primary key is made up of the APDivisionNo+VendorNo+InvoiceNo.

    So you will be better of using the SetKeyValue method for each field in the primary key and then call SetKey without any arguments.

    EDIT: I realized I used SetValue instead of SetKeyValue in the below code previously so i have corrected it.


    oBusObj.SetKeyValue "APDivisionNo$", "00"

    oBusObj.SetKeyValue "VendorNo$", "ABC"

    oBusObj.SetKeyValue "InvoiceNo$", "20190815"

    nRetVal = 0 : nRetVal = oBusObj.SetKey()


  • 0 in reply to David Speck

    Thank you for your reply, I do realize the error is not exactly the error as the vendor code is a string type. I have done all the standard error trapping, it seems to do something with their environment and sage support suggested renaming the links folder and that seemed to allow the record to finally go in, just waiting on the resolution now. There is no reason the record shouldn't have been inserted in normal circumstances.

  • +1 in reply to youngmoon1982
    verified answer

    If renaming the MAS90\Links folder worked, then you have some 3rd party add-ons that are adding additional validation criteria.

    If you need this to work, you may need to reach out to the vendors of the add-ons and try to get more info on what needs to be set in order to pass their validation criteria.

  • 0 in reply to David Speck

    Yes, that is exactly what the problem was. Thank you for helping David.