tCreditorsToUpdate | input | temp-table | |
icDomainCode | input | character | When the domaincode is filled --> Replicate only to this domain. If the domaincode is empty --> Replicate to all domains in this shared set. |
oiReturnStatus | output | integer | Return status of the method. |
MAIN_BLOCK: do on error undo, leave: /* ====================== */ /* Check input parameters */ /* ====================== */ if not can-find(first tCreditorsToUpdate) then return. /* ================== */ /* Exception Handling */ /* ================== */ assign oiReturnStatus = -98 viLocalReturnStatus = 0 vcListAdMstr = '':U. <M-26 run GetAddressTypeId (output viHeadOfficeAddressTypeId (oiHeadOfficeAddressTypeId), output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper. if viLocalReturnStatus < 0 then leave MAIN_BLOCK. CONVERTBLOCK: DO: /* ===================================== */ /* Check which records need to be loaded */ /* ===================================== */ for each tCreditorsToUpdate break by tCreditorsToUpdate.SharedSet_ID: /* ============================================================================================== */ /* Check if the Creditor needs to be replicated to one domain or to all domains of this shared set */ /* If icDomainCode is left blank, all domains for this shared set will be replicated. */ /* ============================================================================================== */ if first-of(tCreditorsToUpdate.SharedSet_ID) then do: <Q-25 run DomainBySharedSetDomain (all) (Read) (Cache) (input tCreditorsToUpdate.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tCreditorsToUpdate.SharedSet_ID) */ /* =============================================================================================== */ /* Get all Mfg Addresses of the DebtorShipTo which are already defined in the database */ /* =============================================================================================== */ <Q-92 run DomainSharedSetForMfgAddress (all) (Read) (NoCache) (input tCreditorsToUpdate.SharedSet_ID, (SharedSetId) input icDomainCode, (DomainCode) input tCreditorsToUpdate.CreditorCode, (Address) output dataset tqDomainSharedSetForMfgAddress) in BDomain > for each tqDomainBySharedSetDomain where tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl: /* ============================================================ */ /* Create a list of all tad_mstr records that need to be loaded */ /* ============================================================ */ if can-find (first tqDomainSharedSetForMfgAddress where tqDomainSharedSetForMfgAddress.tcDomainCode = tqDomainBySharedSetDomain.tcDomainCode and tqDomainSharedSetForMfgAddress.tcad_addr = tCreditorsToUpdate.CreditorCode) then assign vcListAdMstr = vcListAdMstr + (if vcListAdMstr = '':U then '':U else chr(4)) + tqDomainBySharedSetDomain.tcDomainCode + chr(2) + tCreditorsToUpdate.CreditorCode. if length(vcListAdMstr, "CHARACTER") > 10000 then do: /* ========================= */ /* Load the tad_mstr records */ /* ========================= */ <M-68 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 then assign viLocalReturnStatus = viFcReturnSuper. assign vcListAdMstr = '':U. end. /* length */ end. /* for each tqDomainBySharedSetDomain: */ end. /* for each tCreditorsToUpdate */ /* ========================= */ /* Load the tad_mstr records */ /* ========================= */ if vcListAdMstr <> "":U and vcListAdMstr <> ? then do : <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 then assign viLocalReturnStatus = viFcReturnSuper. end. /* if vcListAdMstr <> "":U and */ /* ================================================== */ /* Convert table tCreditorsToUpdate to table tad_mstr */ /* ================================================== */ for each tCreditorsToUpdate break by tCreditorsToUpdate.SharedSet_ID: /* ================================================================================================ */ /* Check if the creditor needs to be replicated to one domain or to all domains of this shared set */ /* If icDomainCode is left blank, all domains for this shared set will be replicated. */ /* ================================================================================================ */ if first-of(tCreditorsToUpdate.SharedSet_ID) then do: if tCreditorsToUpdate.SharedSet_ID = 0 or tCreditorsToUpdate.SharedSet_ID = ? then do: assign vcMessage = trim(substitute(#T-39'The shared set ID for this customer (&1) was not defined.':255(69584)T-39#, trim(string(tCreditorsToUpdate.CreditorCode)) )) viLocalReturnStatus = -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-8270':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> leave CONVERTBLOCK. end. /* if tCreditorsToUpdate.SharedSet_ID = 0 or */ <Q-30 run DomainBySharedSetDomain (all) (Read) (Cache) (input tCreditorsToUpdate.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tCreditorsToUpdate.SharedSet_ID) */ /* ========================================================================= * * Get Address and Contact data of the Mfg Address * * ========================================================================= */ /* Select the HEADOFFICE address */ <Q-82 run AddressForReplication (all) (Read) (Cache) (input tCreditorsToUpdate.BusinessRelation_ID, (BusinessRelationId) input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode) input viHeadOfficeAddressTypeId, (AddressTypeId) output dataset tqAddressForReplication) in BBusinessRelation > find tqAddressForReplication where tqAddressForReplication.tiBusinessRelation_ID = tCreditorsToUpdate.BusinessRelation_ID and tqAddressForReplication.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE} no-lock no-error. if not available tqAddressForReplication then do: assign vcMessage = trim(#T-15'Address record not available for this supplier.':255(69735)T-15#) viLocalReturnStatus = -1. <M-10 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-227425':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> leave CONVERTBLOCK. end. /* if not available tqAddressForReplication */ <Q-7 run ContactByAddress (all) (Read) (Cache) (input tqAddressForReplication.tiAddress_ID, (AddressId) output dataset tqContactByAddress) in BBusinessRelation > for each tqDomainBySharedSetDomain where tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl: /* ============================================================= */ /* Create or update tad_mstr records based on tCreditorsToUpdate */ /* ============================================================= */ find tad_mstr where tad_mstr.ad_addr = tCreditorsToUpdate.CreditorCode and tad_mstr.ad_domain = tqDomainBySharedSetDomain.tcDomainCode no-error. if not available tad_mstr then do: if tCreditorsToUpdate.tc_Status = "D" then next. <M-31 run AddDetailLine (input 'ad_mstr':U (icTable), input '':U (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> if viFcReturnSuper <> 0 then do: assign viLocalReturnStatus = viFcReturnSuper. leave CONVERTBLOCK. end. /* if viFcReturnSuper <> 0 */ end. /* if not available tad_mstr */ else assign tad_mstr.tc_Status = "C":U. assign tad_mstr.ad_addr = tCreditorsToUpdate.CreditorCode tad_mstr.ad_domain = tqDomainBySharedSetDomain.tcDomainCode tad_mstr.ad_bus_relation = tqAddressForReplication.tcBusinessRelationCode tad_mstr.ad_line1 = tqAddressForReplication.tcAddressStreet1 tad_mstr.ad_line2 = tqAddressForReplication.tcAddressStreet2 tad_mstr.ad_line3 = tqAddressForReplication.tcAddressStreet3 tad_mstr.ad_zip = tqAddressForReplication.tcAddressZip tad_mstr.ad_city = tqAddressForReplication.tcAddressCity tad_mstr.ad_state = tqAddressForReplication.tcAddressState tad_mstr.ad_county = tqAddressForReplication.tcCountyCode tad_mstr.ad_state = tqAddressForReplication.tcStateCode tad_mstr.ad_ctry = tqAddressForReplication.tcCountryCode tad_mstr.ad_country = tqAddressForReplication.tcCountryDescription tad_mstr.ad_lang = tqAddressForReplication.tcBusinessRelationLngCode tad_mstr.ad_name = tqAddressForReplication.tcAddressName tad_mstr.ad_sort = tqAddressForReplication.tcAddressSearchName tad_mstr.ad_address_id = tqAddressForReplication.tiAddress_ID tad_mstr.ad_mod_date = tqAddressForReplication.ttLastModifiedDate tad_mstr.ad_type = "supplier":U tad_mstr.ad_taxable = tqAddressForReplication.tlAddressIsTaxable tad_mstr.ad_tax_zone = tqAddressForReplication.tcTxzTaxZone tad_mstr.ad_taxc = tqAddressForReplication.tcTxclTaxCls tad_mstr.ad_tax_usage = tqAddressForReplication.tcTxuTaxUsage tad_mstr.ad_gst_id = tqAddressForReplication.tcAddressTaxIDFederal tad_mstr.ad_pst_id = tqAddressForReplication.tcAddressTaxIDState tad_mstr.ad_misc1_id = tqAddressForReplication.tcAddressTaxIDMisc1 tad_mstr.ad_misc2_id = tqAddressForReplication.tcAddressTaxIDMisc2 tad_mstr.ad_misc3_id = tqAddressForReplication.tcAddressTaxIDMisc3 tad_mstr.ad_format = tqAddressForReplication.tiAddressFormat tad_mstr.ad_userid = tqAddressForReplication.tcLastModifiedUser tad_mstr.ad_phone = substring(tqAddressForReplication.tcAddressTelephone, 1, 20, "CHARACTER") tad_mstr.ad_fax = substring(tqAddressForReplication.tcAddressFax, 1, 20, "CHARACTER") tad_mstr.ad_email = substring(tqAddressForReplication.tcAddressEMail, 1, 48, "CHARACTER") tad_mstr.ad_tax_in_city = tqAddressForReplication.tlAddressIsTaxInCity tad_mstr.ad_coc_reg = tCreditorsToUpdate.CreditorCocNumber tad_mstr.ad_date = (if tad_mstr.ad_date = ? then today else tad_mstr.ad_date) tad_mstr.ad__qad01 = (if tCreditorsToUpdate.CreditorIsTaxInCity then "1":U else ""). if tCreditorsToUpdate.tc_Status = "D":U then do: /* check if address already exists */ <Q-81 run AddressListDetailByDomainCode (all) (Read) (NoCache) (input tCreditorsToUpdate.CreditorCode, (AddressCode) input tad_mstr.ad_domain, (domain) input ?, (AddressType) output dataset tqAddressListDetailByDomainCode) in BMfgAddressListDetail> find first tqAddressListDetailByDomainCode where tqAddressListDetailByDomainCode.tcls_addr = tCreditorsToUpdate.CreditorCode and tqAddressListDetailByDomainCode.tcls_domain = tad_mstr.ad_domain and tqAddressListDetailByDomainCode.tcls_type <> "supplier":U no-lock no-error. if available tqAddressListDetailByDomainCode then assign tad_mstr.tc_Status = tad_mstr.tc_Status. else assign tad_mstr.tc_Status = tCreditorsToUpdate.tc_Status. end. for each tqContactByAddress where tqContactByAddress.tiAddress_ID = tqAddressForReplication.tiAddress_ID: if tqContactByAddress.tlContactIsPrimary then assign ad_attn = tqContactByAddress.tcContactName ad_phone = tqContactByAddress.tcContactTelephone ad_fax = tqContactByAddress.tcContactFax ad_email = tqContactByAddress.tcContactEmail. else if tqContactByAddress.tlContactIsSecondary then assign ad_attn2 = tqContactByAddress.tcContactName ad_phone2 = tqContactByAddress.tcContactTelephone ad_fax2 = tqContactByAddress.tcContactFax ad_email2 = tqContactByAddress.tcContactEmail. end. /* end of for each contact */ end. /* for each tqDomainBySharedSetDomain: */ end. /* for each tCreditorsToUpdate */ end. /* CONVERTBLOCK */ VALIDATEBLOCK: DO: if viLocalReturnStatus < 0 then leave VALIDATEBLOCK. /* ========== */ /* ValidateBC */ /* ========== */ <M-34 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ================== */ /* Additional Updates */ /* ================== */ <M-35 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ======== */ /* DataSave */ /* ======== */ <M-36 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. end. /* VALIDATEBLOCK */ end. /* MAIN_BLOCK */ /* ================== */ /* Exception Handling */ /* ================== */ assign oiReturnStatus = viLocalReturnStatus.
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 = "ApiReplicateFromFinancialsCreditor". 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.apireplicatefromfinancialscreditor.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icDomainCode = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tCreditorsToUpdate"). 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.