Parameters
icBusinessRelationCode | input | character | |
iiAddressID | input | integer | |
tAddressMaster | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bmfgaddress.p)
empty temp-table tAddressMaster.
if icBusinessRelationCode = ""
then do:
assign vcMessageText = #T-25'You must specify a business relation.':40(64360)t-25#
oiReturnStatus = -1.
<M-24 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6783':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
/* First check if the Business relation is active */
<Q-20 run BusinessRelationByCode (all) (Read) (NoCache)
(input icBusinessRelationCode, (BusinessRelationCode)
input viDomainID, (DomainID)
output dataset tqBusinessRelationByCode) in BBusinessRelation >
for first tqBusinessRelationByCode where
tqBusinessRelationByCode.tcBusinessRelationCode = icBusinessRelationCode:
if not (tqBusinessRelationByCode.tlBusinessRelationIsActive)
then do:
assign vcMessageText = #T-22'Business relation $1 is not active.':200(64340)T-22#
oiReturnStatus = -1.
<M-21 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6777':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end. /* not active */
end.
if not available(tqBusinessRelationByCode)
then do:
assign vcMessageText = #T-23'Business relation ($1) is not defined in the system.':120(844)t-23#
oiReturnStatus = -1.
<M-11 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4635':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
/* Retirve the address from the business relation */
<Q-2 run AddressById (all) (Read) (NoCache)
(input iiAddressID, (AddressID)
output dataset tqAddressById) in BBusinessRelation >
/* First make sure it is of type "DOCK" */
for first tqAddressById:
if tqAddressById.tcAddressTypeCode <> "DOCK":U
then do:
assign vcMessageText = trim(substitute(#T-14'No dock address has been defined for business relation (&1).':200(20403)t-14#, icBusinessRelationCode))
oiReturnStatus = -2.
<M-9 run SetMessage
(input vcMessageText (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4634':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
/* Now map it to the tAddressMaster, which is defined like ad_mstr */
for first tMfgBufferFieldMapping where
tMfgBufferFieldMapping.tcMfgTableName = "tAddressMaster":U and
tMfgBufferFieldMapping.tcFinancialTableName = "tqAddressById":U and
tMfgBufferFieldMapping.tcFieldMapping <> "" and
tMfgBufferFieldMapping.tcFieldMapping <> ?:
<M-3 run MappedBufferCopy
(input temp-table tqAddressById:default-buffer-handle (ihSourceBuffer),
input temp-table tAddressMaster:default-buffer-handle (ihTargetBuffer),
input tMfgBufferFieldMapping.tcFieldMapping (icBufferFieldMapping),
input '' (icExcludeFields),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
end.
if not available tqAddressById
then do:
assign vcMessageText = trim(substitute(#T-17'The system cannot find an address with ID &1.':200(20402)t-17#, string(iiAddressID)))
oiReturnStatus = -3.
<M-15 run SetMessage
(input vcMessageText (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4636':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
for first tAddressMaster:
end.
assign tAddressMaster.ad_type = "dock":U.
/* Get the language from the related Business Relation */
<Q-6 run BusinessRelationByIdCode (all) (Read) (NoCache)
(input tqAddressById.tiBusinessRelation_ID, (BusinessRelationId)
input '', (BusinessRelationCode)
output dataset tqBusinessRelationByIdCode) in BBusinessRelation >
/*
* Now map this language to an MFG/PRO language code
* and the business relation code.
*/
for first tqBusinessRelationByIdCode:
assign
tAddressMaster.ad_bus_relation = tqBusinessRelationByIdCode.tcBusinessRelationCode
tAddressMaster.ad_lang = tqBusinessRelationByIdCode.tcLngCode.
end.
/* Get the email details */
<Q-19 run ContactByAddress (all) (Read) (NoCache)
(input iiAddressID, (AddressId)
output dataset tqContactByAddress) in BBusinessRelation >
for each tqContactByAddress:
if tqContactByAddress.tlContactIsPrimary
then assign tAddressMaster.ad_attn = tqContactByAddress.tcContactName
tAddressMaster.ad_phone = tqContactByAddress.tcContactTelephone
tAddressMaster.ad_fax = tqContactByAddress.tcContactFax
tAddressMaster.ad_email = tqContactByAddress.tcContactEmail.
else if tqContactByAddress.tlContactIsSecondary
then assign tAddressMaster.ad_attn2 = tqContactByAddress.tcContactName
tAddressMaster.ad_phone2 = tqContactByAddress.tcContactTelephone
tAddressMaster.ad_fax2 = tqContactByAddress.tcContactFax
tAddressMaster.ad_email2 = tqContactByAddress.tcContactEmail.
end. /* end of for each contact */
/* get the description of the country */
<Q-8 run CountryPrim (all) (Read) (NoCache)
(input tqAddressById.tiCountry_ID, (CountryId)
input '', (CountryCode)
output dataset tqCountryPrim) in BCountry >
find first tqCountryPrim no-error.
if available tqCountryPrim
then assign tAddressMaster.ad_country = tqCountryPrim.tcCountryDescription.
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 = "ApiGetDockAddress".
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.apigetdockaddress.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icBusinessRelationCode = <parameter value>
vhParameter::iiAddressID = <parameter value>.
/* 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.