Description
This method used to maintain the address table by apiAddress and apiContact temp-table. The 2 tables are also input-output parameter so that they can include the addressId when create.Only can address with one businessrelationId or businessrelationCode. For Customer EndUser ExcelIntegration only.
Parameters
tApiAddress | input-output | temp-table | |
tApiContact | input-output | temp-table | |
icBusinessRelationCode | input | character | |
iiBusinessRelationID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bbusinessrelation.p)
assign oiReturnStatus = -98.
if iiBusinessRelationID = 0
then do:
/* Verify the Business Relation */
<Q-27 run BusinessRelationPrim (all) (Read) (NoCache)
(input '', (BusinessRelationId)
input icBusinessRelationCode, (BusinessRelationCode)
output dataset tqBusinessRelationPrim) in BBusinessRelation >
for first tqBusinessRelationPrim:
assign iiBusinessRelationID = tqBusinessRelationPrim.tiBusinessRelation_ID.
end.
end.
if iiBusinessRelationID = 0
then do:
assign
vcMessageText = #T-31'$1 is not a valid business relation code.':50(55559)t-31#
oiReturnStatus = -3.
<M-30 run SetMessage
(input vcMessageText (icMessage),
input icBusinessRelationCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8607':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
return.
end.
/* Load the business relation record */
<M-24 run DataLoad
(input '' (icRowids),
input iiBusinessRelationID (icPkeys),
input '' (icObjectIds),
input '' (icFreeform),
input true (ilKeepPrevious),
output viFcreturnsuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
end.
/* Go through the addresses passed in */
for each tApiAddress BY tc_rowid:
/* Check to see if the address exists already - try first with address id or else with unique keys */
find tAddress
where tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid
and tAddress.Address_ID = tApiAddress.Address_ID no-error.
if not available tAddress and
tApiAddress.AddressLogicKeyString <> ""
then find tAddress
where tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid
and tAddress.AddressLogicKeyString = tApiAddress.AddressLogicKeyString
and tAddress.tcAddressTypeCode = tApiAddress.tcAddressTypeCode no-error.
if not available tAddress
then find first tAddress
where tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid
and tAddress.AddressStreet1 = tApiAddress.AddressStreet1
and tAddress.AddressStreet2 = tApiAddress.AddressStreet2
and tAddress.AddressStreet3 = tApiAddress.AddressStreet3
and tAddress.AddressZip = tApiAddress.AddressZip
and tAddress.AddressCity = tApiAddress.AddressCity
and tAddress.tcAddressTypeCode = tApiAddress.tcAddressTypeCode no-error.
/* if we have a tAddress record it means that we are doing an update */
if available tAddress
then do:
/* if we are deleting this record then delete it otherwise update the record */
if tApiAddress.tc_Status = "D":U
then
assign tAddress.tc_status = "D":U.
else do:
assign tAddress.tc_Status = "":U.
/* Check if anything has changed. */
buffer-compare tApiAddress except
AddressLogicKeyString
Address_ID
BusinessRelation_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_status
to tAddress save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tAddress.tc_Status = "C":U.
end.
end. /* if available tAddress */
else do:
/* no address record exists so we need to create one */
<M-23 run AddDetailLine (input 'Address':U (icTable),
input tBusinessRelation.tc_rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
end. /* not if available tAddress */
if tAddress.tc_status <> "D":U
then
buffer-copy tApiAddress except
AddressLogicKeyString
Address_ID
BusinessRelation_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_status
to tAddress.
/* Store the address id in the api table */
assign
tApiAddress.Address_Id = tAddress.Address_ID
tApiAddress.BusinessRelation_ID = tAddress.BusinessRelation_ID.
if tAddress.tc_status <> "D":U
then do:
/* process the contact information */
for each tApiContact
where tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid:
find tContact where
tContact.tc_ParentRowid = tAddress.tc_Rowid and
tContact.ContactName = tApiContact.ContactName
no-error.
if not available tContact
then find tContact where
tContact.tc_ParentRowid = tAddress.tc_Rowid and
tContact.Contact_ID = tApiContact.Contact_ID
no-error.
/* ================================= */
/* Check for Create / Update */
/* ================================= */
if available tContact
then do:
assign tContact.tc_Status = "":U.
buffer-compare tApiContact except
Contact_ID
Address_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_status
to tContact save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tContact.tc_Status = "C":U.
end. /* if available tContact */
else do:
<M-29 run AddDetailLine (input 'Contact':U (icTable),
input tAddress.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* NOY if available tContact */
buffer-copy tApiContact except
Contact_ID
Address_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_Status
to tContact.
assign
tApiContact.Contact_ID = tContact.Contact_ID.
end. /* for each tApiContact where ... */
end. /* End tAddress.tc_stutus = "D" */
end. /* end for each tApiAddress */
/* Validate the business relation componenet */
<M-28 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
/* run any addtionalupdates */
<M-25 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
/* save the componenet */
<M-26 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
if oiReturnStatus = -98
then oiReturnStatus = 0.