| tApiDebtorEndUser | input | temp-table | |
| icAction | input | character | Action. Possible values; "SAVE":U "SAVESTORE":U "STORE":U "VALIDATE":U |
| ocLstPrimKey | output | character | LstPrimKey Char4 separated list with the primary keys of the newly created main-table records. The fields of a primkey are separated with Char2. E.g. 1<Char2>2002<Char2>100<Char4>1<Char2>2002<Char2>101 |
| ocLstReturn | output | character | LstReturn Char4 separated list with the return-status of the newly created main-table records. Zero means no errors occured. E.g. 0<Char4>-1<Char4>-504<Char4>1<Char4>0 |
| ocLstRowid | output | character | LstRowid Char4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. . E.g. -1<Char2>aox00098001<Char2>-26 |
| oiReturnStatus | output | integer | Return status of the method. |
/* ========================================== */
/* Method info: */
/* EndUser will be loaded based on the Logical Key */
/* ========================================== */
/* ========================================================================= */
/* Clear the instance: */
/* this will also clear the t_s tables that were filled ApiMaintainByDataset */
/* ========================================================================= */
<M-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* ==================== */
/* Set default return */
/* Parameter validation */
/* ==================== */
assign oiReturnStatus = -98
vlDraftInstanceCreated = false.
if icAction = ? then assign icAction = "":U.
if icAction <> {&DAEMONACTION-SAVESTORE} and
icAction <> {&DAEMONACTION-SAVE} and
icAction <> {&DAEMONACTION-STORE} and
icAction <> {&DAEMONACTION-VALIDATE}
then do:
assign vcMessage = trim(subst(#T-1'End User integration: the specified action (&1) should be in the list '&2'.':255(70402)T-1#,
icAction,
"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
oiReturnStatus = -1.
<M-3 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8443':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
return.
end.
/* =================== */
/* Count Debtor End user records */
/* =================== */
for each tApiDebtorEndUser no-lock:
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end.
if viMainTableRecordCount = 0
then do:
assign vcMessage = trim(#T-4'End User integration: no main table records found.':255(70403)T-4#)
oiReturnStatus = -1.
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8444':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
return.
end.
<Q-15 run DebtorEndUserPrim (Start) in BDebtorEndUser >
for each tApiDebtorEndUser by tApiDebtorEndUser.tc_Rowid:
MAIN-BLOCK:
DO:
/* ========== */
/* Initialize */
/* ========== */
assign vcMessage = "":U
vcRowID = "":U
vlWarningsFound = false.
vlSaveAsDraft = icAction = {&DAEMONACTION-STORE}.
/* ====================================== */
/* Get the DebtorEndUser_ID based on the logical key */
/* ====================================== */
if (tApiDebtorEndUser.DebtorEndUser_ID = ? or
tApiDebtorEndUser.DebtorEndUser_ID = 0) and
tApiDebtorEndUser.DebtorEndUserCode <> "" and
tApiDebtorEndUser.DebtorEndUserCode <> ?
then do:
<Q-6 run DebtorEndUserPrim (all) (Read) (NoCache)
(input tApiDebtorEndUser.DebtorEndUserCode, (DebtorEndUserCode)
input ?, (DebtorEndUser_ID)
input viCompanyId, (CompanyId)
output dataset tqDebtorEndUserPrim) in BDebtorEndUser >
find first tqDebtorEndUserPrim where
tqDebtorEndUserPrim.tcDebtorEndUserCode = tApiDebtorEndUser.DebtorEndUserCode
no-error.
if available tqDebtorEndUserPrim
then assign tApiDebtorEndUser.DebtorEndUser_ID = tqDebtorEndUserPrim.tiDebtorEndUser_ID.
end. /* if (tApiDebtorEndUser.DebtorEndUser_ID = ? or ...*/
if tApiDebtorEndUser.DebtorEndUser_ID = ? or
tApiDebtorEndUser.DebtorEndUser_ID = 0
then assign viFcReturnSuper = -4.
else do:
<M-8 run DataLoad
(input '':U (icRowids),
input string(tApiDebtorEndUser.DebtorEndUser_ID) (icPkeys),
input '':U (icObjectIds),
input '' (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end.
if viFcReturnSuper = -4
then do:
assign viFcReturnSuper = 0.
<M-9 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-7'Cannot create a new instance. Error number: &1.':255(14310)t-7#, string(viFcReturnSuper))).
find first tDebtorEndUser no-error.
end. /* if viFcReturnSuper = -4 */
else do:
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-10'Cannot load the instance (error number: &1, instance ID: &2).':255(16295)t-10#,
string(viFcReturnSuper),
string(tApiDebtorEndUser.DebtorEndUser_ID))).
else do:
find tDebtorEndUser where
tDebtorEndUser.DebtorEndUser_ID = tApiDebtorEndUser.DebtorEndUser_ID
no-error.
if not available tDebtorEndUser
then assign vcMessage = trim(subst(#T-11'Cannot find the instance after it has been loaded (instance ID: &1).':255(16296)t-11#,
string(tApiDebtorEndUser.DebtorEndUser_ID))).
else do:
assign tDebtorEndUser.tc_Status = "C":U.
/* check if anything has changed */
buffer-compare tApiDebtorEndUser except
tApiDebtorEndUser.tc_Rowid
tApiDebtorEndUser.tc_Status
tApiDebtorEndUser.tc_ParentRowid
tApiDebtorEndUser.Address_ID
tApiDebtorEndUser.Debtor_ID
tApiDebtorEndUser.LastModifiedDate
tApiDebtorEndUser.LastModifiedTime
tApiDebtorEndUser.LastModifiedUser
tApiDebtorEndUser.tiDebtorBusinessRelation_ID
tApiDebtorEndUser.tiAddressBusinessRelation_ID
to tDebtorEndUser
save vcResult.
if vcResult <> '':U and
vcResult <> ?
then assign tDebtorEndUser.tc_Status = "C":U.
else assign tDebtorEndUser.tc_Status = "":U.
end.
end. /* if viFcReturnSuper < 0 */
end. /* if viFcReturnSuper = -4 */
/* ====================================== */
/* Check for errors in the previous block */
/* ====================================== */
if vcMessage <> "":U
then do:
assign ocLstReturn = ocLstReturn + chr(4) + (if viFcReturnSuper = 0 then "-3":U else string(viFcReturnSuper))
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-32 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8541':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave MAIN-BLOCK.
end. /* if vcMessage <> "":U */
/* ================ */
/* Copy data for Debtor End User */
/* ================ */
buffer-copy tApiDebtorEndUser
except tApiDebtorEndUser.DebtorEndUser_ID
tApiDebtorEndUser.SharedSet_ID
tApiDebtorEndUser.tc_ParentRowid
tApiDebtorEndUser.tc_Rowid
tApiDebtorEndUser.tc_Status
tApiDebtorEndUser.DebtorEndUserCode
to tDebtorEndUser.
if tDebtorEndUser.tc_Status = 'N':U
then assign tDebtorEndUser.DebtorEndUserCode = tApiDebtorEndUser.DebtorEndUserCode.
assign vcRowID = tDebtorEndUser.tc_Rowid
tApiDebtorEndUser.DebtorEndUser_ID = tDebtorEndUser.DebtorEndUser_ID. /*Needed to set the prim-key after the Save*/
/*
/* =================================================== */
/* This is where it ends if only SaveAsDraft is needed */
/* =================================================== */
if vlSaveAsDraft
then do:
assign ocLstReturn = ocLstReturn + chr(4) + "-1":U
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U.
leave MAIN-BLOCK.
end. /* if vlSaveAsDraft */
*/
/* =============================== */
/* Set Actvity & Validate the data */
/* =============================== */
if can-find (first tDebtorEndUser where
tDebtorEndUser.tc_Status = "N":U)
then assign vcActivityCode = "Create":U.
else if can-find (first tDebtorEndUser where
tDebtorEndUser.tc_Status = "C":U)
then assign vcActivityCode = "Modify":U.
empty temp-table tApiEnduserAddress.
empty temp-table tApiEnduserContact.
<Q-38 run AddressById (all) (Read) (NoCache)
(input tApiDebtorEndUser.Address_ID, (AddressID)
output dataset tqAddressById) in BBusinessRelation >
find first tqAddressById no-error.
if available tqAddressById
then do:
create tApiEnduserAddress.
<M-39 run BufferCopy
(input buffer tqAddressById:handle (ihFrom),
input buffer tApiEnduserAddress:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0 then
assign oiReturnStatus = viFcReturnSuper.
end.
/* Tax Zone */
<Q-40 run TaxZoneByTaxZone (all) (Read) (NoCache)
(input ?, (TxzTaxZone)
output dataset tqTaxZoneByTaxZone) in BMfgTaxZone >
find first tqTaxZoneByTaxZone no-error.
assign tApiEnduserAddress.AddressStreet1 = tApiDebtorEndUser.tcAddressStreet1
tApiEnduserAddress.AddressCity = tApiDebtorEndUser.tcAddressCity
tApiEnduserAddress.AddressStreet2 = tApiDebtorEndUser.tcAddressStreet2
tApiEnduserAddress.AddressStreet3 = tApiDebtorEndUser.tcAddressStreet3
tApiEnduserAddress.AddressZip = tApiDebtorEndUser.tcAddressZip
tApiEnduserAddress.AddressName = tApiDebtorEndUser.tcAddressName
tApiEnduserAddress.AddressTelephone = tApiDebtorEndUser.tcAddressTelephone
tApiEnduserAddress.AddressEmail = tApiDebtorEndUser.tcAddressEmail
tApiEnduserAddress.AddressFax = tApiDebtorEndUser.tcAddressFax
tApiEnduserAddress.AddressWebSite = tApiDebtorEndUser.tcAddressWebSite
tApiEnduserAddress.AddressIsTemporary = tApiDebtorEndUser.tlAddressIsTemporary
tApiEnduserAddress.AddressWebSite = tApiDebtorEndUser.tcAddressWebSite
/* tApiEnduserAddress.State_ID = tqAddressById.tiState_ID
tApiEnduserAddress.AddressState = tApiDebtorEndUser.tcStateCode
*/
tApiEnduserAddress.tcAddressTypeCode = tApiDebtorEndUser.tcAddressTypeCode
tApiEnduserAddress.TxzTaxZone = (if available tqTaxZoneByTaxZone then tqTaxZoneByTaxZone.tctxz_tax_zone else "":U).
<Q-41 run ContactByAddress (all) (Read) (NoCache)
(input tApiDebtorEndUser.Address_ID, (AddressId)
output dataset tqContactByAddress) in BBusinessRelation >
find first tqContactByAddress no-error.
if available tqContactByAddress
then do:
create tApiEnduserContact.
<M-42 run BufferCopy
(input buffer tqContactByAddress:handle (ihFrom),
input buffer tApiEnduserContact:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0 then
assign oiReturnStatus = viFcReturnSuper.
end.
/* ================= */
/* Validate the data */
/* ================= */
<M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave MAIN-BLOCK.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ================ */
/* External updates */
/* ================ */
<M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave MAIN-BLOCK.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ============= */
/* Save the data */
/* ============= */
if icAction <> {&DAEMONACTION-VALIDATE}
then do:
<M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave MAIN-BLOCK.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end. /* if icAction <> {&DAEMONACTION-VALIDATE} */
/* ============================================ */
/* Indicate that everything was saved correctly */
/* ============================================ */
assign ocLstReturn = ocLstReturn + chr(4) + (if vlWarningsFound = true then "1":U else "0":U)
ocLstPrimKey = ocLstPrimKey + chr(4) + string(tApiDebtorEndUser.DebtorEndUser_ID)
ocLstRowid = ocLstRowid + chr(4) + vcRowID.
END. /* MAIN-BLOCK */
/* ================================================================== */
/* Handle errors: Store if SaveAsDraft is needed */
/* Check: only 1 draft is allowed for a single bus-component instance */
/* ================================================================== */
if vlSaveAsDraft and
index(substr(ocLstReturn, r-index(ocLstReturn, chr(4)) + 1,-1,"CHARACTER":U),"-":U) <> 0 /* Negative return-status for this entry */
then do:
if vlDraftInstanceCreated = true
then do:
assign vcMessage = trim(#T-33'Only one draft instance can be created per method call.':255(858)T-33#) + chr(10) + trim(#T-34'This second object will not be stored as a draft instance and so is an error.':255(859)t-34#).
<M-36 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8543':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
next.
end. /* if vlDraftInstanceCreated = true */
<M-37 run StoreState
(input '(':U + string(tDebtorEndUser.DebtorEndUserCode) + ') ':U + #T-36'End User created via an API method.':255(70987)T-36# (icDescription),
input ? (icUIClass),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
assign vlDraftInstanceCreated = true
entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiDebtorEndUser.DebtorEndUser_ID)
entry(num-entries(ocLstRowid , chr(4)), ocLstRowid , chr(4)) = vcRowID.
end. /* if vlSaveAsDraft and substr */
end. /* for each tApiDebtorEndUser by tApiDebtorEndUser.tc_Rowid:*/
<Q-16 run DebtorEndUserPrim (Stop) in BDebtorEndUser >
/* ============================================================ */
/* Trim the first character of ocLstReturn and primkey */
/* Check for correct number and format of the return-parameters */
/* ============================================================ */
if length(ocLstReturn, "CHARACTER":U) > 1
then assign ocLstReturn = substring(ocLstReturn, 2, -1, "CHARACTER":U).
if length(ocLstPrimKey, "CHARACTER":U) > 1
then assign ocLstPrimKey = substring(ocLstPrimKey, 2, -1, "CHARACTER":U).
if length(ocLstRowid, "CHARACTER":U) > 1
then assign ocLstRowid = substring(ocLstRowid, 2, -1, "CHARACTER":U).
if num-entries(ocLstReturn, chr(4)) <> viMainTableRecordCount or
num-entries(ocLstPrimKey, chr(4)) <> viMainTableRecordCount or
num-entries(ocLstRowid, chr(4)) <> viMainTableRecordCount
then do:
assign vcMessage = trim(#T-22'End User Integration: Incomplete information returned by an API method. See other messages for further details.':200(70983)T-22#) + chr(10) +
trim(#T-23'Main table records':100(70980)T-23#) + "=":U + string(viMainTableRecordCount) + chr(10) +
trim(#T-24'Return statuses':100(70981)T-24#) + "=":U + ocLstReturn + chr(10) +
trim(#T-25'Primary keys':100(70982)T-25#) + "=":U + ocLstPrimKey + chr(10) +
trim(#T-26'Row IDs':100(300)T-26#) + "=":U + ocLstRowid
oiReturnStatus = -3.
<M-29 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8537':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
return.
end.
/* ===================================================== */
/* Set global return status based on the individual ones */
/* ===================================================== */
if ocLstReturn = substring(fill("0":U + chr(4), viMainTableRecordCount), 1, length(ocLstReturn, "CHARACTER":U), "CHARACTER":U)
then assign oiReturnStatus = 0.
else do:
if index(ocLstReturn, "-":U) <> 0
then do:
assign vcMessage = trim(#T-27'An error has occurred while running this API method. See other error messages for more details.':255(301)T-27#)
oiReturnStatus = -1.
<M-30 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8538':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end.
else do:
assign vcMessage = trim(#T-28'A warning has occurred while running this API method. See other error messages for more details.':255(302)T-28#)
oiReturnStatus = +1.
<M-31 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8539':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end.
end.define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BDebtorEndUser".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiStdMaintainTT".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bdebtorenduser.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tApiDebtorEndUser").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.