project QadFinancials > class BDomain > method ApiSynchronise

Description

ApiSynchronise method used for Domain

Specific:
Create the QAD domain and make it the system domain if needed.


Parameters


olUpdatesDoneoutputlogical
oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BSystem.ApiSynchroniseCustom2


program code (program/bdomain.p)

<ANCESTOR-CODE>

if oiReturnStatus < 0
then return.

assign oiReturnStatus = -98
       olUpdatesDone  = false
       vcDomainCode   = 'QAD':U.       
       
/* ============================================================================================= */
/* Retrieve the system Domain. In case it already exists and it is the QAD domain we can return  */
/* In case the system domain does not exist yet:                                                 */
/*   - In case the QAD domain exists, we will mark it as the system domain.                      */
/*   - In case the QAD domain does not exist, we will create it and mark it as the system domain */
/* ============================================================================================= */
<Q-24 run DomainsByDomainType (all) (Read) (NoCache)
   (input 0, (DomainID)
    input {&DOMAINSDOMAINTYPE-SYSTEM}, (DomainType)
    output dataset tqDomainsByDomainType) in BDomain >       

find first tqDomainsByDomainType where
           tqDomainsByDomainType.tcDomainType = {&DOMAINSDOMAINTYPE-SYSTEM}
           no-error.

/* Check if the QAD domain exists */
<Q-8 assign vlFcQueryRecordsAvailable = DomainsPrim (NoCache)
   (input 0, (DomainID)
    input vcDomainCode, (DomainCode)) in BDomain >

/* In case the QAD domain exist and a system domain exists, we return */
if available tqDomainsByDomainType and vlFcQueryRecordsAvailable
then do:
     if oiReturnStatus = -98
     then assign oiReturnStatus = 0.  
     return.
end.

if vlFcQueryRecordsAvailable = false 
then do:
    /* Create the QAD domain and make it the system domain if needed */
    <M-18 run DataNew  (output viFcReturnSuper (oiReturnStatus)) in BDomain>
    
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    
    if viFcReturnSuper < 0
    then return.    
    
    /* Fill the domains fields */
    assign tDomains.DomainCode     = vcDomainCode
           tDomains.DomainDatabase = 'QADDB':U
           tDomains.DomainIsActive = true
           tDomains.DomainPropath  = '':U
           tDomains.tcLngCode      = 'US':U
           tDomains.DomainType     = if not available tqDomainsByDomainType 
                                     then {&DOMAINSDOMAINTYPE-SYSTEM}
                                     else '':U.
end.
else do :
    /* No System domain exists. Make QAD domain the system domain */
    assign vcFreeform = "for each Domains where Domains.DomainCode = '":U + vcDomainCode + "'":U. 
    
    <M-25 run DataLoad
       (input  '':U (icRowids), 
        input  '':U (icPkeys), 
        input  '':U (icObjectIds), 
        input  vcFreeForm (icFreeform), 
        input  false (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BDomain>
        
     find first tDomains no-error.
     if not available tDomains
     then return.     
     
     assign tDomains.tc_Status  = 'C':U
            tDomains.DomainType = {&DOMAINSDOMAINTYPE-SYSTEM}.                                     
end.

if tDomains.DomainType = {&DOMAINSDOMAINTYPE-SYSTEM}
then do :
    /* Set the SYSTEM domain switch  */
    <I-20 {bFcOpenInstance
         &CLASS           = "Session"}>
     
    <M-21 run SetLogicalValue
       (input  'AllowSystemDomainChange':U (icName), 
        input  true (ilValue), 
        output viExternalReturnStatus (oiReturnStatus)) in Session> 

    <I-22 {bFcCloseInstance
         &CLASS           = "Session"}> 
                    
    if viExternalReturnStatus <> 0
    then assign oiReturnStatus = viExternalReturnStatus.
                    
    if viExternalReturnStatus < 0
    then return.
end.

/* Fill the DomainsProperty fields */
find tDomainPropertyRefer where
     tDomainPropertyRefer.Domain_ID = tDomains.Domain_ID
     no-lock no-error.
if not available tDomainPropertyRefer
then do:
    assign vcMessage    = trim(#T-11'The domain property record for the newly created domain cannot be found.':222(73471256)T-11#)
           oiReturnStatus = -1.
    <M-12 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  tDomains.tc_Rowid (icRowid), 
        input  'QadFin-5453':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDomain>                
    return.        
end.

assign tDomainPropertyRefer.DomainPropertyName         = "System Domain":U
       tDomainPropertyRefer.DomainPropertySearchName   = "System Domain":U
       tDomainPropertyRefer.DomainPropertyIsSetupCompl = false
       tDomainPropertyRefer.tcCurrencyCode             = "USD":U
       tDomainPropertyRefer.tcStatutoryCurrencyCode    = tDomainPropertyRefer.tcCurrencyCode.

/* create domainsharedset lines */
assign vcListSharedSetTypeCode = <M-14 GetSharedSetTypes
                                    () in BDomain>
       viNumberOfEntries       = num-entries(vcListSharedSetTypeCode, chr(2))
       viEntry                 = 1.

<Q-23 run SharedSetByType (all) (Read) (NoCache)
   (input true, (SharedSetIsActive)
    input '':U, (SharedSetTypeCode)
    output dataset tqSharedSetByType) in BSharedSet >
       
/* for every SharedSetType find the correct DomainSharedSet record and update it */
do while viEntry + 1 <= viNumberOfEntries:

    find first tqSharedSetByType where
               tqSharedSetByType.tcSharedSetTypeCode                           = entry(viEntry + 1, vcListSharedSetTypeCode, chr(2)) and
              (substring(tqSharedSetByType.tcSharedSetCode,1,7, "CHARACTER":U) = "Default":U or
               tqSharedSetByType.tcSharedSetCode                               = entry(viEntry, vcListSharedSetTypeCode, chr(2)))
               no-lock no-error.
    if not available tqSharedSetByType
    then do:
        assign vcMessage      = trim(substitute(#T-16'Cannot find a default shared set of type &1 to link to this domain.':255(733751236)T-16#, entry(viEntry + 1, vcListSharedSetTypeCode, chr(2)) ))
               oiReturnStatus = -1.

        <M-17 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  tDomains.tc_Rowid (icRowid), 
            input  'QadFin-5457':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDomain>
        return.
    end. /* if not available tqSharedSetOfType */                   

    find tDomainSharedSet where
         tDomainSharedSet.Domain_ID           = tDomains.Domain_ID   and
         tDomainSharedSet.tcSharedSetTypeCode = entry(viEntry + 1, vcListSharedSetTypeCode, chr(2))
         no-lock no-error.
    if available tDomainSharedSet
    then assign tDomainSharedSet.tcSharedSetCode = tqSharedSetByType.tcSharedSetCode
                tDomainSharedSet.SharedSet_ID    = tqSharedSetByType.tiSharedSet_ID.
    assign viEntry = viEntry + 2.        
end. /* do while viEntry + 1 <= viNumberOfEntries: */

/* Validate Data */
<M-6 run ValidateBC
   (output viFcReturnSuper (oiReturnStatus)) in BDomain>
   
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.

/* Additional Updates */
<M-5 run AdditionalUpdates
   (output viFcReturnSuper (oiReturnStatus)) in BDomain>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.

/* DataSave */
<M-4 run DataSave
   (output viFcReturnSuper (oiReturnStatus)) in BDomain>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.

assign olUpdatesDone  = true.  
       
if oiReturnStatus = -98
then assign oiReturnStatus = 0.


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 = "BDomain".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSynchronise".
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 = "".

/* 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.