Description
With this method a Payment Condition can be added, modified or deleted.
Parameters
tApiPaymentCondition | input | temp-table | |
tApiPaymentConditionStaged | input | temp-table | |
icAction | input | character | |
ocLstPrimKey | output | character | |
ocLstReturn | output | character | |
ocLstRowId | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program7/bpaymentcondition.p)
/* ================================================== */
/* Method info: */
/* PaymentCondition will be loaded based on the logical key */
/* ================================================== */
/* ============================================================================= */
/* Clear the instance: */
/* this will also clear the t_s tables that where filled in ApiMaintainByDataset */
/* ============================================================================= */
<M-16 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
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 vcPaymentConditionMsg = trim(subst(#T-1'A credit terms integration error occurred. The specified action (&1) must be in the list '&2'.':255(69739)t-1#,
trim(icAction),
"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-STORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-VALIDATE}":U))
oiReturnStatus = -1.
<M-17 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8272':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
return.
end. /*if icAction <> {&DAEMONACTION-SAVESTORE} and*/
/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiPaymentCondition no-lock:
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end.
if viMainTableRecordCount = 0
then do:
assign vcPaymentConditionMsg = trim(#T-2'A credit terms integration error occurred. The system cannot find main table records (SAF structure).':255(69740)t-2#)
oiReturnStatus = -1.
<M-18 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8273':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
return.
end. /*if viMainTableRecordCount = 0*/
/* ============= */
/* Start queries */
/* ============= */
<Q-19 run PaymentConditionPrim (Start) in BPaymentCondition >
/* ================================ */
/* Start loop on main-table records */
/* ================================ */
for each tApiPaymentCondition by tApiPaymentCondition.tc_Rowid:
main-block: do:
/* ========== */
/* Initialize */
/* ========== */
assign vcPaymentConditionMsg = '':U
vcRowId = '':U
vlWarningsFound = false
vlSaveAsDraft = icAction = {&DAEMONACTION-STORE}.
/* ============================================== */
/* Get the PaymentCondition_ID based on the logical key */
/* ============================================== */
if (tApiPaymentCondition.PaymentCondition_ID = ? or
tApiPaymentCondition.PaymentCondition_ID = 0) and
tApiPaymentCondition.PaymentConditionCode <> ? and
tApiPaymentCondition.PaymentConditionCode <> '':U
then do:
<Q-20 run PaymentConditionPrim (all) (Read) (NoCache)
(input ?, (PaymentConditionId)
input tApiPaymentCondition.PaymentConditionCode, (PaymentConditionCode)
output dataset tqPaymentConditionPrim) in BPaymentCondition >
find tqPaymentConditionPrim where
tqPaymentConditionPrim.tcPaymentConditionCode = tApiPaymentCondition.PaymentConditionCode
no-lock no-error.
if available tqPaymentConditionPrim
then assign tApiPaymentCondition.PaymentCondition_ID = tqPaymentConditionPrim.tiPaymentCondition_ID.
end. /* if (tApiPaymentCondition.PaymentCondition_ID = ? or */
/* ====================== */
/* Load/Create PaymentCondition */
/* ====================== */
if tApiPaymentCondition.PaymentCondition_ID = ? or
tApiPaymentCondition.PaymentCondition_ID = 0
then assign viFcReturnSuper = -4.
else do:
<M-21 run DataLoad
(input ? (icRowids),
input string(tApiPaymentCondition.PaymentCondition_ID) (icPkeys),
input ? (icObjectIds),
input ? (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
end. /* NOT if tApiPaymentCondition.PaymentCondition_ID = ? or */
if viFcReturnSuper = -4
then do:
assign viFcReturnSuper = 0.
<M-22 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
if viFcReturnSuper < 0
then assign vcPaymentConditionMsg = trim(subst(#T-3'Cannot create a new instance. Error number &1.':255(14463)t-3#,string(viFcReturnSuper))).
find first tPaymentCondition no-error.
end. /* if viFcReturnSuper = -4 */
else do:
if viFcReturnSuper < 0
then assign vcPaymentConditionMsg = trim(subst(#T-4'Cannot load the instance. Error number &1.':255(14464)t-4#,string(viFcReturnSuper))).
else do:
find tPaymentCondition where
tPaymentCondition.PaymentCondition_ID = tApiPaymentCondition.PaymentCondition_ID
no-lock no-error.
if not available tPaymentCondition
then assign vcPaymentConditionMsg = trim(subst(#T-5'Cannot find the instance &1 after it has been loaded.':255(14465)t-5#,string(tApiPaymentCondition.PaymentCondition_ID))).
else assign tPaymentCondition.tc_Status = 'C':U.
end. /* NOT if viFcReturnSuper < 0 */
end. /* NOT if viFcReturnSuper = -4 */
/* ====================================== */
/* Check for errors in the previous block */
/* ====================================== */
if vcPaymentConditionMsg <> '':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-23 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8274':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
leave main-block.
end. /* if vcPaymentConditionMsg <> '':U */
/* ======================== */
/* Copy data for PaymentCondition */
/* ======================== */
buffer-copy tApiPaymentCondition except
PaymentCondition_ID
PaymentConditionCode
tc_ParentRowid
tc_Rowid
tc_Status
to tPaymentCondition.
if tPaymentCondition.tc_Status = 'N':U
then assign tPaymentCondition.PaymentConditionCode = tApiPaymentCondition.PaymentConditionCode.
assign vcRowId = tPaymentCondition.tc_Rowid
tApiPaymentCondition.PaymentCondition_ID = tPaymentCondition.PaymentCondition_ID.
/*needed to set the prim-key after the save*/
/* =========================================== */
/* Process all Child tables (PaymentConditionStaged) */
/* =========================================== */
<M-33 run ApiStdMaintainTTDetail
(input icAction (icAction),
input-output ocLstReturn (bcLstReturn),
input-output ocLstPrimKey (bcLstPrimKey),
input-output ocLstRowId (bcLstRowId),
input-output vlSaveAsDraft (blSaveAsDraft),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
if viFcReturnSuper < 0
then leave main-block.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* =================================================== */
/* 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 activity */
/* ============ */
if can-find(first tPaymentCondition where
tPaymentCondition.tc_Status = 'N':U)
then assign vcActivityCode = 'Create':U.
else if can-find(first tPaymentCondition where
tPaymentCondition.tc_Status = 'C':U)
then assign vcActivityCode = 'Modify':U.
/* ================= */
/* Validate the data */
/* ================= */
<M-24 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
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. /* if viFcReturnSuper < 0 */
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ================ */
/* External updates */
/* ================ */
<M-25 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
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. /* if viFcReturnSuper < 0 */
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ============= */
/* Save the data */
/* ============= */
if icAction <> {&DAEMONACTION-VALIDATE}
then do:
<M-26 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
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. /* if viFcReturnSuper < 0 */
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 then '1':U else '0':U)
ocLstPrimKey = ocLstPrimKey + chr(4) + string(tApiPaymentCondition.PaymentCondition_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(substring(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 vcPaymentConditionMsg = trim(#T-6'Only one draft instance can be created per method call.':255(13856)T-6#) +
chr(10) +
trim(#T-7'This second object cannot be stored as a draft instance and so is an error.':255(13879)t-7#).
<M-27 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8275':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
next.
end. /* if vlDraftInstanceCreated = true */
<M-28 run StoreState
(input '(':U + string(tPaymentCondition.PaymentConditionCode) + ')':U + trim(#T-8'The credit terms were created using an API method.':200(69741)t-8#) (icDescription),
input ? (icUIClass),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
assign vlDraftInstanceCreated = true
entry(num-entries(ocLstReturn, chr(4)), ocLstReturn, chr(4)) = string(viFcReturnSuper)
entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiPaymentCondition.PaymentCondition_ID)
entry(num-entries(ocLstRowId, chr(4)), ocLstRowId, chr(4)) = vcRowId.
end. /* if vlSaveAsDraft and */
end. /* for each tApiPaymentCondition by tApiPaymentCondition.tc_Rowid: */
/* ============ */
/* Stop queries */
/* ============ */
<Q-29 run PaymentConditionPrim (Stop) in BPaymentCondition >
/* ============================================================ */
/* Trim the first character of ocLstReturn en 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 vcPaymentConditionMsg = trim(#T-9'A credit terms integration error occurred. An API method returned incomplete information. See other messages for further details.':255(69742)t-9#) +
chr(10) +
trim(substitute(#T-10'Main table records: &1.':255(310)T-10#,string(viMainTableRecordCount))) + chr(10) +
trim(substitute(#T-11'Return Statuses: &1.':255(311)T-11#,ocLstReturn)) + chr(10) +
trim(substitute(#T-12'Primary keys: &1.':255(312)T-12#,ocLstPrimKey)) + chr(10) +
trim(substitute(#T-13'Row IDs: &1.':255(313)T-13#,ocLstRowid))
oiReturnStatus = -3.
<M-30 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8276':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
return.
end. /* if num-entries */
/* ===================================================== */
/* 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 vcPaymentConditionMsg = trim(#T-14'An error has occurred while running this API method. See other error messages for more details.':255(301)T-14#)
oiReturnStatus = -1.
<M-31 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8277':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
end. /* if index(ocLstReturn,"-":U) <> 0 */
else do:
assign vcPaymentConditionMsg = trim(#T-15'A warning has occurred while running this API method. See other error messages for more details.':255(302)T-15#)
oiReturnStatus = +1.
<M-32 run SetMessage
(input vcPaymentConditionMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8278':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
end. /* not if index(ocLstReturn,"-":U) <> 0 */
end. /* not if ocLstReturn */
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
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 = "BPaymentCondition".
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/bpaymentcondition.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tApiPaymentCondition").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tApiPaymentConditionStaged").
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.