ludi
New Member
Good day guys the below code i created to copy data from ttCustomer date to ttContacts table, i have assign that the ContactID should be auto generated using the GUID format. yet im getting an error as follow
@test.
METHOD PUBLIC VOID test_Contacts():
DEFINE VARIABLE hChangeDataSet AS HANDLE NO-UNDO.
DEFINE VARIABLE hdsCustomerBE AS HANDLE NO-UNDO.
DEFINE VARIABLE filter AS CHARACTER NO-UNDO.
DEFINE VARIABLE myUUID AS RAW NO-UNDO.
DEFINE VARIABLE ContactID AS CHARACTER NO-UNDO FORMAT "x(36)" LABEL "Contact ID".
/* Empty the dataset */
DATASET dsCustomerBE:EMPTY-DATASET().
/* Retrieve data from Business Entity */
RUN SI_GetContactsData IN hSISportsERPProc (INPUT filter, OUTPUT DATASET dsCustomerBE).
/* Output to a log file */
OUTPUT TO "C:\OpenEdge\DevOps\application\Log\Test_AddContacts.out".
/* Enable tracking changes to the ttContacts table */
TEMP-TABLE ttContacts:TRACKING-CHANGES = TRUE.
/* Generate or assign ContactID for each record in ttContacts */
FOR EACH ttContacts:
ASSIGN
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())).
END.
/* Create ttContacts records from ttCustomer */
FOR EACH ttCustomer:
CREATE ttContacts.
ASSIGN
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())) /* Auto-generate ContactID */
ttContacts.ParentID = STRING(ttCustomer.CustNum)
ttContacts.ContactName = ttCustomer.Name
ttContacts.ContactPerson = ttCustomer.Contact
ttContacts.Address[1] = ttCustomer.Address
ttContacts.Address[2] = ttCustomer.Address2
ttContacts.ContactNumber[1] = ttCustomer.Phone
ttContacts.ContactEmail = ttCustomer.EmailAddress.
END.
/* Disable tracking changes to the ttContacts table */
TEMP-TABLE ttContacts:TRACKING-CHANGES = FALSE.
/* Create the dynamic dataset that will hold the changes */
CREATE DATASET hChangeDataSet.
/* Copy the schema from the Business Entity's dataset to the change dataset */
hdsCustomerBE = DATASET dsCustomerBE:HANDLE.
hChangeDataSet:CREATE-LIKE(hdsCustomerBE).
/* Copy the before and after tables for the changed records to the change dataset */
hChangeDataSet:GET-CHANGES(hdsCustomerBE).
/* Call the UpdateData() method for the Business Entity */
RUN SI_UpdateData IN hSISportsERPProc (INPUT-OUTPUT DATASET-HANDLE hChangeDataSet).
/* Merge the changes made in the Business Entity to the dsCustomerBE dataset */
hChangeDataSet:MERGE-CHANGES(hdsCustomerBE, TRUE).
DELETE OBJECT hChangeDataSet NO-ERROR.
/* Output the results after merge */
MESSAGE "**************Contacts after merge ****************".
FIND FIRST ttContacts NO-ERROR.
IF AVAILABLE(ttContacts) THEN
DO:
MESSAGE " " ttContacts.ContactID
" " ttContacts.ParentID
" " ttContacts.ContactName
" " ttContacts.ContactNumber[1]
" " ttContacts.ContactEmail SKIP.
END.
/* Confirm again by re-retrieving the data from the Business Entity */
DATASET dsCustomerBE:EMPTY-DATASET().
RUN SI_GetContactsData IN hSISportsERPProc (INPUT filter, OUTPUT DATASET dsCustomerBE).
/* Output the results after re-retrieval */
MESSAGE "**************Contacts after re-retrieval ****************".
FIND FIRST ttContacts NO-ERROR.
IF AVAILABLE(ttContacts) THEN
DO:
MESSAGE " " ttContacts.ContactID
" " ttContacts.ParentID
" " ttContacts.ContactName
" " ttContacts.ContactNumber[1]
" " ttContacts.ContactEmail SKIP.
END.
/* Close the output */
OUTPUT CLOSE.
RETURN.
END METHOD.
@test.
METHOD PUBLIC VOID test_Contacts():
DEFINE VARIABLE hChangeDataSet AS HANDLE NO-UNDO.
DEFINE VARIABLE hdsCustomerBE AS HANDLE NO-UNDO.
DEFINE VARIABLE filter AS CHARACTER NO-UNDO.
DEFINE VARIABLE myUUID AS RAW NO-UNDO.
DEFINE VARIABLE ContactID AS CHARACTER NO-UNDO FORMAT "x(36)" LABEL "Contact ID".
/* Empty the dataset */
DATASET dsCustomerBE:EMPTY-DATASET().
/* Retrieve data from Business Entity */
RUN SI_GetContactsData IN hSISportsERPProc (INPUT filter, OUTPUT DATASET dsCustomerBE).
/* Output to a log file */
OUTPUT TO "C:\OpenEdge\DevOps\application\Log\Test_AddContacts.out".
/* Enable tracking changes to the ttContacts table */
TEMP-TABLE ttContacts:TRACKING-CHANGES = TRUE.
/* Generate or assign ContactID for each record in ttContacts */
FOR EACH ttContacts:
ASSIGN
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())).
END.
/* Create ttContacts records from ttCustomer */
FOR EACH ttCustomer:
CREATE ttContacts.
ASSIGN
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())) /* Auto-generate ContactID */
ttContacts.ParentID = STRING(ttCustomer.CustNum)
ttContacts.ContactName = ttCustomer.Name
ttContacts.ContactPerson = ttCustomer.Contact
ttContacts.Address[1] = ttCustomer.Address
ttContacts.Address[2] = ttCustomer.Address2
ttContacts.ContactNumber[1] = ttCustomer.Phone
ttContacts.ContactEmail = ttCustomer.EmailAddress.
END.
/* Disable tracking changes to the ttContacts table */
TEMP-TABLE ttContacts:TRACKING-CHANGES = FALSE.
/* Create the dynamic dataset that will hold the changes */
CREATE DATASET hChangeDataSet.
/* Copy the schema from the Business Entity's dataset to the change dataset */
hdsCustomerBE = DATASET dsCustomerBE:HANDLE.
hChangeDataSet:CREATE-LIKE(hdsCustomerBE).
/* Copy the before and after tables for the changed records to the change dataset */
hChangeDataSet:GET-CHANGES(hdsCustomerBE).
/* Call the UpdateData() method for the Business Entity */
RUN SI_UpdateData IN hSISportsERPProc (INPUT-OUTPUT DATASET-HANDLE hChangeDataSet).
/* Merge the changes made in the Business Entity to the dsCustomerBE dataset */
hChangeDataSet:MERGE-CHANGES(hdsCustomerBE, TRUE).
DELETE OBJECT hChangeDataSet NO-ERROR.
/* Output the results after merge */
MESSAGE "**************Contacts after merge ****************".
FIND FIRST ttContacts NO-ERROR.
IF AVAILABLE(ttContacts) THEN
DO:
MESSAGE " " ttContacts.ContactID
" " ttContacts.ParentID
" " ttContacts.ContactName
" " ttContacts.ContactNumber[1]
" " ttContacts.ContactEmail SKIP.
END.
/* Confirm again by re-retrieving the data from the Business Entity */
DATASET dsCustomerBE:EMPTY-DATASET().
RUN SI_GetContactsData IN hSISportsERPProc (INPUT filter, OUTPUT DATASET dsCustomerBE).
/* Output the results after re-retrieval */
MESSAGE "**************Contacts after re-retrieval ****************".
FIND FIRST ttContacts NO-ERROR.
IF AVAILABLE(ttContacts) THEN
DO:
MESSAGE " " ttContacts.ContactID
" " ttContacts.ParentID
" " ttContacts.ContactName
" " ttContacts.ContactNumber[1]
" " ttContacts.ContactEmail SKIP.
END.
/* Close the output */
OUTPUT CLOSE.
RETURN.
END METHOD.