project QadFinancials > class BOpenItemAdjustment > method ExitInstance

Description

This method can be extended with code to execute when an instance of a business class is stopped.

Standard functionality in this method is
- Clean up instance data in the fcInstance table.
- Create or update a draft instance if applicable.

plus transaction handling
- Remove the instance from the transaction if it was added to a transaction in InitInstance.
- Abort the transaction if one was started from inside the business code.

PreCondition

This method is executed when :
- A business instance is stopped (release object + delete instance data)
(icDraftReference = "" + viCurrentDraftInstanceId = 0)
- A business instance is saved as a draft (release object + create draft)
(icDraftReference <> "")
- A draft instance is stopped (release object, delete copy of draft, release original draft)
(icDraftReference = "" + viCurrentDraftInstanceId <> 0)

This method is NOT run when a business instance is only closed (release object + keep instance data).


Parameters


icDraftReferenceinputcharacterDescription for the draft instance.
This parameter will have a value when creating a draft instance.
icDraftFormNameinputcharacterThis parameter will have a value when creating a draft instance.
ilDraftIsSharedinputlogicalThis parameter will have a value when creating a draft instance.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bopenitemadjustment.p)

<ANCESTOR-CODE>

/* ====================================================================================== */
/* Release or store the WHT number                                                        */
/* WHT Numbers are retrieved in BCInvoice, BBankEntry, BCDocument and BOpenItemAdjustment */
/* The Numbers are committed in BWithHoldingTax.PostSave                                  */
/* ====================================================================================== */
if viCurrentDraftInstanceId = 0
then do:
    /* The WHT Numbers that are retrieved are stored in a data item, since the normal temp-table can be cleared when errors occured somewhere */
    do viReleaseNumberCount = num-entries(vcReleaseWHTNumberList, chr(4)) to 1 by -1
        on error undo, throw:
        
        assign viReleaseWHTNumber = integer(entry(viReleaseNumberCount, vcReleaseWHTNumberList, chr(4))) no-error.
        if error-status:error 
        then do:                 
            assign vcMessage      = trim(substitute(#T-34'Error releasing WHT Number.':255(183355101)T-34#))  + chr(10) +                                
                                    trim(substitute(#T-80'WHT Number List: &1':255(517036178)T-80#, trim(vcReleaseWHTNumberList))).
                   oiReturnStatus = -3.
            <M-45 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'S':U (icType), 
                input  2 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-535328':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
             return.
         end.  /* if error-status:error */          
        
        assign vhFcComponent = ?.
        if icDraftReference = "":U
        then do:
            <M-28 run ReleaseNumber
               (input  viCompanyId (iiCompanyId), 
                input  9999 (iiNumbrYear), 
                input  'WHT':U (icNumbrType), 
                input  viReleaseWHTNumber (iiNumbr), 
                input  viFcCurrentInstanceId (iiInstanceId), 
                input  vcFcComponentName (icClassName), 
                output viFcReturnSuper (oiReturnStatus)) in BNumber>
        end.
        else do:
            <M-18 run StoreNumber
               (input  viCompanyId (iiCompanyID), 
                input  9999 (iiNumbrYear), 
                input  'WHT':U (icNumbrType), 
                input  viReleaseWHTNumber (iiNumbr), 
                output viFcReturnSuper (oiReturnStatus)) in BNumber>
        end.
        if viFcReturnSuper <> -4 and /* it can be that the number is already committed in BWHT */
           (viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0))
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.    
    
    end. /* do viReleaseNumberCount from num-entries(vcReleaseWHTNumberList, chr(4)) to 1 by -1: */
end. /* if viCurrentDraftInstanceId = 0 */