Jump to content

Sage 50 Accounts v27 API returns first SalesRecord rather than the searched on Find


 Share

Recommended Posts

Hi, we noticed that there is at least 1 customer account not included in the retrieval of SalesRecords when running the import for some reason and we aren't sure why.

From the whole import, this illustrates the problem, post-import in the database you can see there is no A10006 - the missing account in question

image.png.3004268d676dc7f1230a613875ab90fd.png

In SAGE (N.B. we don't import Inactive accounts)

image.thumb.png.93fcce6ab55add4c9aab6614c8a666d4.png

Can see there by comparison that inactive accounts are missing as expected and for some inexplicable reason A10006 which looks OK is omitted from the API call.

In order to check further we started using the Find method to figure out if we could 'grab' the missing account.  Following the documentation if we run a find for ANY customer code which we know to be present and even imported through to the application we are just returned the first customer account in the list regardless of what we search for.

We note that using the find does only bring back the 1 record though, so it's not like it starts iterating through the whole list as it does when we omit the search.  It seems the partial find also acts in exactly the same way for some reason.  

From the documentation:

' ************** Complete Match on Sales Record object **********************

    ' Create Sales Record Object
    Set oSalesRecord = oWS.CreateObject("SalesRecord")

    ' Populate index field with value to search for 
    oSalesRecord.Fields.Item("ACCOUNT_REF").Value = CStr("CASH001")

    ' Perform Exact match find
    bFlag = oSalesRecord.Find(False)

    If bFlag Then

      MsgBox "The find has been successful, the object is positioned to " & _
        oSalesRecord.Fields.Item("NAME").Value, vbOKOnly Or vbInformation, "SDO"

    Else

      MsgBox "The find has not found a match to your criteria", vbOKOnly Or vbInformation, "SDO"

    End If

    ' ************** Partial Match on Purchase Record object *******************

    ' Create the Purchase Record Object 
    Set oPurchaseRecord = oWS.CreateObject("PurchaseRecord")

    ' Populate index field with value to search for
    oPurchaseRecord.Fields.Item("ACCOUNT_REF").Value = CStr("S")  

    ' Perform partial match find
    bFlag = oPurchaseRecord.Find(True)

    If bFlag Then

      MsgBox "The find has been successful, the object is positioned to " & _
        oPurchaseRecord.Fields.Item("NAME").Value, vbOKOnly Or vbInformation, "SDO"

    Else

      MsgBox "The find has not found a match to your criteria.", vbOKOnly Or vbInformation, "SDO"

    End If

From our code:

// Get SAGE definition
                SalesRecord oRecord = (SalesRecord)Mandatory.Sage50Workspace.CreateObject("SalesRecord");

                // Handle specific search if requested
                bool searchingForSpecificRecord = false;
                if (custID != null)
                {
                    searchingForSpecificRecord = true;
                    ConsoleNotification.Notify(ConsoleNotification.MessageType.INFORMATION, $"Specific Customer Account Download Requested {custID}");

                    // Set filter
                    oRecord.Fields.Item("ACCOUNT_REF").Value = custID;

                    // Lookup in SAGE (import will be as per below within the loop if we get a hit)
                    bool dataToImport = oRecord.Find(false);
                    if (!dataToImport)
                    {
                        ConsoleNotification.Notify(ConsoleNotification.MessageType.ERROR, $"Cannot find Customer Account with Reference {custID} in SAGE");
                        return new IntegrationActionResult()
                        {
                            Success = false,
                            ErrorMessage = $"Cannot find Customer Account with Reference {custID} in SAGE"
                        };
                    }
                }

Output result (exact match custID = "P10044") - shows output from lower in the code than the example above - it finds the record and imports but the record is always A10004

image.png.d463eeea0c359cdb7b947c8f2e9835fc.png

Output result (partial match "P") -- shows output from lower in the code than the example above - it finds the record and imports but the record is always A10004

image.png.11743cbc29ba6b79d79a279dd69e20ca.png

Not sure if there's 1 or 2 problems here.  Something seems off in the Find Method but if there's some corruption of the data or something in SAGE it could be the same reason why the account isn't pulled through?

We've done a reindex on customers and a compression, we've checked for errors - can't see anything obvious.

Anyone got any ideas?

 

 
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...