Copying Data from ttCustomer to ttContacts

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
1716199107877.png

@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.
 
I think this line is the problem:

Code:
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())). /* Auto-generate ContactID */

If you change to this instead it compiles:

Code:
ttContacts.ContactID = STRING(GUID(GENERATE-UUID)). /* Auto-generate ContactID */
 
i created a data-relation that the ttContacts ParentID is the CustNum Child from ttCustomer table.
{include/ttCustomer.i {&ClassAccess}}
{include/ttOrder.i {&ClassAccess}}
{include/ttOrderLine.i {&ClassAccess}}
{include/ttSalesRep.i {&ClassAccess}}
{include/ttContacts.i {&ClassAccess}}

Define {&ClassAccess} dataset dsCustomerBE for ttSalesRep, ttCustomer, ttOrder, ttOrderLine, ttContacts
data-relation CustomerSalesReps for ttCustomer, ttSalesRep
relation-fields(SalesRep, SalesRep)
data-relation CustomerOrders for ttCustomer, ttOrder
relation-fields(CustNum, CustNum)
data-relation OrderOrderLines for ttOrder, ttOrderLine
relation-fields(OrderNum, OrderNum)
data-relation CustomerContacts for ttCustomer, ttContacts
relation-fields(CustNum, ParentID)
.

1716200728492.png
 
It seems you have quite a few errors - could be in the include files - and not easy to see the problem as there appears to be missing datasets/function names and some code lines not being quite correct as similar to the GUID error in the () being used for GENERATE-UUID.

Maybe an idea to create a few simple procedures similar to these and if these work fine then add all the extras one stage at a time which will hopefully track down the causes:

 
I think this line is the problem:

Code:
ttContacts.ContactID = STRING(GUID(GENERATE-UUID())). /* Auto-generate ContactID */

If you change to this instead it compiles:

Code:
ttContacts.ContactID = STRING(GUID(GENERATE-UUID)). /* Auto-generate ContactID */

You can save yourself some typing and just use the GUID function without an argument. The GUID function also returns a character value, so you don't need to use the STRING function either.

Code:
ttContacts.ContactID = GUID. /* Auto-generate ContactID *
 
Back
Top