Actian GUID fields and Entity References

SOLVED

Hello,

I've written two programs that work together to generate real time reports out of Sage 50c.  One program uses the SDK to create, update and delete data in Sage while the other uses ODBC to make sure the report data stays up to date.  It's working well but I've had to use some workarounds. 

The SDK has to look up items by values such as "ReferenceNumber" or "ItemID" while the ODBC client uses database id values like "VendorRecordNumber" or "PostOrder".  I would like to use the same unique identifying property in both programs.

After toying around with entity references in the SDK and the GUID fields stored in Actian I noticed that they are identical except that apparently the Endianness of the first three sections is reversed, for example:

EntityReference: 7a7a6d2e-cef3-4de2-aad3-de19643aecd4
corresponds with GUID: 2E6D7A7A-F3CE-E24D-AAD3-DE19643AECD4

So I've actually got 2 questions:

  1. If I reverse the byte order of the first 3 sections of the GUID can I do something like: Sage.Peachtree.API.EntityReference.Create<Sage.Peachtree.API.PurchaseOrder>(new Guid("7a7a6d2e-cef3-4de2-aad3-de19643aecd4")).Load(CompanyRef)
  2. Can the Sage SDK do that work for me another way?
  • 0

    Hello, if you subscribe to our Developer Partner Program, we can open a support ticket on the questions and escalate it to our developer team for an authoritative answer. The minimum fee is $350 for the first year and $250 to renew in the following years. Please send your business name, address and phone number to [email protected] and we will get back to you with more information. Thanks!

  • +1
    verified answer

    I appreciate the reply.  This was something that was just too intriguing so I went off on my own and tested my hypothesis.

    Just in case someone else is wondering, it turns out that you don't need to reverse the byte order of the first three sections.  In my case all I had to do was convert these sections into their corresponding data types (uint, short, short) and .NET, C#, Windows, Intel, or somebody along the way did it for me.  But it works.

    Here's a small function I wrote that creates a Guid in C# that you can use in EntityReference.Create:

    private static Guid CreateGuidFromDbGUID(string dbGuidStr)
    {
        System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowHexSpecifier;
    
        string[] rawSections = dbGuidStr.Split(new char[1] { '-' });
    
        byte[] a = BitConverter.GetBytes(uint.Parse(rawSections[0], style));
        byte[] b = BitConverter.GetBytes(short.Parse(rawSections[1], style));
        byte[] c = BitConverter.GetBytes(short.Parse(rawSections[2], style));
    
        string guidStr = BitConverter.ToString(a).Replace("-", string.Empty) +
            BitConverter.ToString(b).Replace("-", string.Empty) +
            BitConverter.ToString(c).Replace("-", string.Empty) +
            rawSections[3] +
            rawSections[4];
    
        return Guid.Parse(guidStr);
    }
    

    You can get the value for the parameter "dbGuidStr" from ODBC by casting the field to a unique identifier so it will come out looking like this: DE7961C5-DD35-F94E-B694-5AD6B20FCE55 instead of running together like this: DE7961C5DD35F94EB6945AD6B20FCE55

    Run that value through the function above and produce an entity reference from the Guid it returns, like so:

    EntityReference<PurchaseOrder> eRef = EntityReference.Create<PurchaseOrder>(CreateGuidFromDbGUID(dbGuidStr));
    return eRef.Load(company);

    And there's your purchase order.

    You still need all your ODBC inner joins and your references in the SDK, but for me its good to know that there is a single point of reference that can transition between the two and refer to the exact same entity.

    I've only tested this on a small scale at this point so it might not pan out in the long run.  If it doesn't I'll post another reply.  In the mean time though I'm going include these Guid fields in all my data sets.