project QadFinancials > class BMfgAddress > method ApiReplicateFromFinancialsBusRel
Description
Replicate changes of the Address to operational database.
Parameters
Internal usage
QadFinancials
program code (program9/bmfgaddress.p)
/* ====================== */
/* Check input parameters */
/* ====================== */
if not can-find(first tAddressesToUpdate)
then return.
/* ================================================ */
/* We check if the replication to ad_mstr is needed */
/* ================================================ */
assign vlReplicationEnabled = true.
<I-31 {bFcOpenInstance
&CLASS = "Session"}>
<M-68 run GetLogicalValue
(input 'ReplicationEnabled':U (icName),
output vlReplicationEnabled (olValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<I-49 {bFcCloseInstance
&CLASS = "Session"}>
if vlReplicationEnabled = FALSE
then return.
MAIN_BLOCK:
do on error undo, leave:
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0
vcListAdMstr = '':U.
CONVERTBLOCK:
DO:
/* ===================================== */
/* Check which records need to be loaded */
/* ===================================== */
for each tAddressesToUpdate where
tAddressesToUpdate.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
if tAddressesToUpdate.tc_Status = "":U and
not can-find(first tContactsToUpdate where
tContactsToUpdate.tc_ParentRowid = tAddressesToUpdate.tc_Rowid and
tContactsToUpdate.tc_Status <> "":U)
then next.
/* ============================================================================================== */
/* Get all MfgAddresses which which are created based on this one */
/* ============================================================================================== */
<Q-55 run AddressByFinancialAddress (all) (Read) (NoCache)
(input tAddressesToUpdate.Address_ID, (AddressID)
output dataset tqAddressByFinancialAddress) in BMfgAddress >
for each tqAddressByFinancialAddress where
tqAddressByFinancialAddress.tiad_address_id = tAddressesToUpdate.Address_ID:
assign vcListAdMstr = vcListAdMstr
+ (if vcListAdMstr = '':U then '':U else chr(4))
+ tqAddressByFinancialAddress.tcad_domain
+ chr(2) + tqAddressByFinancialAddress.tcad_addr.
if length(vcListAdMstr, "CHARACTER") > 30000
then do:
/* ========================= */
/* Load the tad_mstr records */
/* ========================= */
<M-53 run DataLoad
(input '':U (icRowids),
input vcListAdMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
assign vcListAdMstr = '':U.
end. /* length */
end. /* for each tqAddressByFinancialAddress where */
end. /* for each tAddressesToUpdate where */
/* ========================================================================================= *
* Load data to the memory instance *
* ========================================================================================= */
if length(vcListAdMstr, "CHARACTER") > 0
then do:
/* ========================= */
/* Load the tad_mstr records */
/* ========================= */
<M-27 run DataLoad
(input '':U (icRowids),
input vcListAdMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
assign vcListAdMstr = '':U.
end.
/* Update Mfg/pro addresses */
for each tAddressesToUpdate:
if tAddressesToUpdate.tc_Status = "":U and
not can-find(first tContactsToUpdate where
tContactsToUpdate.tc_ParentRowid = tAddressesToUpdate.tc_Rowid and
tContactsToUpdate.tc_Status <> "":U)
then next.
/* Get Mfg addresses to upload */
for each tad_mstr where
tad_mstr.ad_address_id = tAddressesToUpdate.Address_ID :
assign tad_mstr.ad_line1 = tAddressesToUpdate.AddressStreet1
tad_mstr.ad_line2 = tAddressesToUpdate.AddressStreet2
tad_mstr.ad_line3 = tAddressesToUpdate.AddressStreet3
tad_mstr.ad_zip = tAddressesToUpdate.AddressZip
tad_mstr.ad_city = tAddressesToUpdate.AddressCity
tad_mstr.ad_state = tAddressesToUpdate.AddressState
tad_mstr.ad_county = tAddressesToUpdate.tcCountyCode
tad_mstr.ad_country = tAddressesToUpdate.tcCountryDescription
tad_mstr.ad_state = tAddressesToUpdate.tcStateCode
tad_mstr.ad_ctry = tAddressesToUpdate.tcCountryCode
tad_mstr.ad_lang = tAddressesToUpdate.tcLngCode
tad_mstr.ad_name = tAddressesToUpdate.AddressName
tad_mstr.ad_sort = tAddressesToUpdate.AddressSearchName
tad_mstr.ad_address_id = tAddressesToUpdate.Address_ID
tad_mstr.ad_mod_date = tAddressesToUpdate.LastModifiedDate
tad_mstr.ad_taxable = tAddressesToUpdate.AddressIsTaxable
tad_mstr.ad_tax_zone = tAddressesToUpdate.TxzTaxZone
tad_mstr.ad_taxc = tAddressesToUpdate.TxclTaxCls
tad_mstr.ad_tax_usage = tAddressesToUpdate.TxuTaxUsage
tad_mstr.ad_gst_id = tAddressesToUpdate.AddressTaxIDFederal
tad_mstr.ad_pst_id = tAddressesToUpdate.AddressTaxIDState
tad_mstr.ad_misc1_id = tAddressesToUpdate.AddressTaxIDMisc1
tad_mstr.ad_misc2_id = tAddressesToUpdate.AddressTaxIDMisc2
tad_mstr.ad_misc3_id = tAddressesToUpdate.AddressTaxIDMisc3
tad_mstr.ad_format = tAddressesToUpdate.AddressFormat
tad_mstr.ad_userid = tAddressesToUpdate.LastModifiedUser
tad_mstr.ad_phone = substring(tAddressesToUpdate.AddressTelephone, 1, 20, "CHARACTER")
tad_mstr.ad_fax = substring(tAddressesToUpdate.AddressFax, 1, 20, "CHARACTER")
tad_mstr.ad_email = substring(tAddressesToUpdate.AddressEMail, 1, 48, "CHARACTER")
tad_mstr.ad_tax_in_city = tAddressesToUpdate.AddressIsTaxInCity
tad_mstr.ad_tax_in = tAddressesToUpdate.AddressIsTaxIncluded
tad_mstr.tc_Status = tAddressesToUpdate.tc_Status
tad_mstr.ad_attn = "":U
tad_mstr.ad_attn2 = "":U
tad_mstr.ad_phone2 = "":U
tad_mstr.ad_fax2 = "":U
tad_mstr.ad_email2 = "":U.
for each tContactsToUpdate where
tContactsToUpdate.tc_ParentRowid = tAddressesToUpdate.tc_Rowid and
tContactsToUpdate.tc_Status <> "D":U:
if tContactsToUpdate.ContactIsPrimary
then assign tad_mstr.ad_attn = tContactsToUpdate.ContactName
tad_mstr.ad_phone = tContactsToUpdate.ContactTelephone
tad_mstr.ad_fax = tContactsToUpdate.ContactFax
tad_mstr.ad_email = tContactsToUpdate.ContactEmail.
if tContactsToUpdate.ContactIsSecondary
then assign tad_mstr.ad_attn2 = tContactsToUpdate.ContactName
tad_mstr.ad_phone2 = tContactsToUpdate.ContactTelephone
tad_mstr.ad_fax2 = tContactsToUpdate.ContactFax
tad_mstr.ad_email2 = tContactsToUpdate.ContactEmail.
end. /* end of for each contact */
end. /* for each tqDomainBySharedSetDomain: */
end. /* for each tDebtorEndUsersToUpdate */
end. /* CONVERTBLOCK */
/* If there are not changed records, just skip all extra steps */
if not can-find(first tad_mstr where
tad_mstr.tc_Status <> "":U)
then leave MAIN_BLOCK.
VALIDATEBLOCK:
DO:
/* ========== */
/* ValidateBC */
/* ========== */
<M-72 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
/* ================== */
/* Additional Updates */
/* ================== */
<M-91 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
/* ======== */
/* DataSave */
/* ======== */
<M-17 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end. /* VALIDATEBLOCK */
end. /* MAIN_BLOCK */
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.
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 = "BMfgAddress".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiReplicateFromFinancialsBusRel".
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/bmfgaddress.apireplicatefromfinancialsbusrel.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tAddressesToUpdate").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tContactsToUpdate").
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.