1. Erick Ruiz
  2. PowerBuilder
  3. Sunday, 20 September 2020 01:07 AM UTC

I need to generate a random UUID for a invoice request using Rest/xml endpoint.  I will appreciate any help on how to create a function in PB that can generate a UUID.

Thanks

Who is viewing this page
Accepted Answer
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Monday, 21 September 2020 07:37 AM UTC
  2. PowerBuilder
  3. # Permalink

PB Function that generate UUID

Long ll_rc

sr_uuid lstr_uuid
string ls_guid = ""

constant long RPC_S_OK = 0
constant long RPC_S_UUID_LOCAL_ONLY = 1824
constant long RPC_S_UUID_NO_ADDRESS = 1739

ll_rc = uuidCreate(lstr_uuid)

// returns
// RPC_S_OK - The call succeeded.
// RPC_S_UUID_LOCAL_ONLY -
// The UUID is guaranteed to be unique to this computer only.
// RPC_S_UUID_NO_ADDRESS -
// Cannot get Ethernet/token-ring hardware address for this computer.

IF ll_rc <> RPC_S_OK THEN
setNull(ls_GUID)
ELSE
If as_type = 'F' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B93-2641-477A-C99E-A2FFEBEB214A
Elseif as_type = 'R' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B932641477AC99EA2FFEBEB214A
End If
End If

Return ls_guid

 

Need to declare this external function

FUNCTION long uuidCreate(ref sr_uuid astr_uuid) LIBRARY "Rpcrt4.dll"  ALIAS FOR "UuidCreate"

 

Comment
  1. Sivaprakash BKR
  2. Monday, 21 September 2020 07:40 AM UTC
How to call ?

of_generate_uuid('R') or of_generate('F')

  1. Helpful
  1. Erick Ruiz
  2. Sunday, 27 September 2020 23:08 PM UTC
Thank you for the information and code. I really appreciate.

I need to ask you a question which I couldn't solve.



What is the definition of the structure that you have to pass a referencie en the function declared as sr_uuid.

Thxs
  1. Helpful
  1. Sivaprakash BKR
  2. Monday, 28 September 2020 01:25 AM UTC
Structure sr_uuid

----------------------

unsignedlong data1

unsignedinteger data2

unsignedinteger data3

unsignedinteger data4[4]

  1. Helpful
There are no comments made yet.
Erick Ruiz Accepted Answer Pending Moderation
  1. Wednesday, 30 September 2020 03:41 AM UTC
  2. PowerBuilder
  3. # 1

Thank you Sivaprakash BKR It worked well.  I appreciate.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 28 September 2020 19:35 PM UTC
  2. PowerBuilder
  3. # 2

Hi Sivaprakash  et Al;

   Have a look at my STD Framework in the "nc_app_controller_master" object class within the STD-FC_PB_Base.PBL. In there you will find the "of_generate_uuid" method for UUID generation. In the same PBL library, you will also see the required "sr_uuid" structure for passing to the MS-Windows API's. All the API's definitions you need are also in the "nc_app_controller_master" object class's External Function declarations.

   FYI:  https://sourceforge.net/projects/stdfndclass/files/FrameWork/Integrated

  Note that both the Structure and the code need to drive the UUID creation are wrong in these postings. You will also see that you need a few other SDK calls as well. For example: getting the correct formatting of the UUID returned by the O/S. Allso, the amount of code you need is about 5 lines and it runs lightening fast. Way less code than what is posted here.

HTH

Regards ... Chris

 

Comment
  1. Sivaprakash BKR
  2. Tuesday, 29 September 2020 05:49 AM UTC
Thanks Chris,

I'm using the code posted here in a couple of projects for few years, without any issues so far. Nevertheless I'll go though your code too, will incorporate / change in my newer project(s).

In the meantime, Erick could tell us whether the code that I posted is running without issues or not.

  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Sunday, 20 September 2020 05:00 AM UTC
  2. PowerBuilder
  3. # 3

I "cheated";

  1. Created .NET Standard 2.0 library in C#
  2. Create class with function byte[] GetNewGUID( )
    .NET has GUID class with constructor to create new GUID
  3. Let PB .NET assembly importer create .NET interop class in PowerScript.
    byte[ ] translates into BLOB in PowerScript.
  4. Call that class's of_GetNewGuid( )
  5. I added GetNewGuidAsText( ) to return GUID formatted as string
    Again that is standard functionality in .NET

So my PowerScript win32 app uses .NET Core system classes to generate GUIDs and convert between binary and text formats.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.