project QadFinancials > class BMfgAddress > method ApiGetHeadOfficeAddress
Parameters
| icBusinessRelationCode | input | character | |
| 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-24'You must specify a business relation.':40(64360)T-24#
oiReturnStatus = -1.
<M-22 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6782':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
/* First check if the record exists */
<Q-15 run BusinessRelationByCode (all) (Read) (NoCache)
(input icBusinessRelationCode, (BusinessRelationCode)
input viDomainID, (DomainID)
output dataset tqBusinessRelationByCode) in BBusinessRelation >
/* If we have a valid business relation - check that its active */
for first tqBusinessRelationByCode
where tqBusinessRelationByCode.tcBusinessRelationCode = icBusinessRelationCode:
if not(tqBusinessRelationByCode.tlBusinessRelationIsActive)
then do:
assign
vcMessageText = #T-20'Business relation $1 is not active.':200(64340)T-20#
oiReturnStatus = -1.
<M-19 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6776':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
end. /* not active */
end.
/* if none available raise error */
if not available tqBusinessRelationByCode then
do:
assign
vcMessageText = #T-21'Business relation ($1) is not defined in the system.':120(844)T-21#
oiReturnStatus = -1.
<M-16 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4904':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
/* Retirve the address from the business relation */
<Q-14 run AddressByType (all) (Read) (NoCache)
(input tqBusinessRelationByCode.tiBusinessRelation_ID, (BusinessRelationID)
input 'HEADOFFICE':U, (AddressType)
output dataset tqAddressByType) in BBusinessRelation >
for first tqAddressByType:
/* 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-5 run MappedBufferCopy (input temp-table tqAddressByType: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 tqAddressByType then do:
assign
vcMessageText = #T-12'No head office address was defined for business relation '&1'.':200(15793)T-12#
oiReturnStatus = -2.
<M-6 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4658':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
return.
end.
find first tAddressMaster exclusive-lock no-error.
/* Get the language from the related Business Relation */
<Q-7 run BusinessRelationByIdCode (all) (Read) (NoCache)
(input tqAddressByType.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.
*/
/* Mapping no longer needed as Mfg and Fin languages are equal */
for first tqBusinessRelationByIdCode:
assign
tAddressMaster.ad_bus_relation = tqBusinessRelationByIdCode.tcBusinessRelationCode
tAddressMaster.ad_lang = tqBusinessRelationByIdCode.tcLngCode.
end.
/* Get the email details */
<Q-18 run ContactByAddress (all) (Read) (NoCache)
(input tqAddressByType.tiAddress_ID, (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-9 run CountryPrim (all) (Read) (NoCache)
(input tqAddressByType.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 = "ApiGetHeadOfficeAddress".
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.apigetheadofficeaddress.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icBusinessRelationCode = <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.