Is it possible to follow the behavior of Internal storages of Type Amount to UDFs such that Dr or cr

Discussion in 'Knowledge Base' started by admin, May 17, 2013.

    
  1. admin

    admin Administrator Staff Member


    Query:
    Is it possible to follow the behavior of Internal storages of Type Amount to UDFs such that Debit or Credit values of UDF get set automatically to these Fields based on some other Methods?

    By default, the internal storages of Type Amounts like Opening Balance, Credit Limit, etc. are pre-set by the platform to automatically set Debit or Credit values based on the value of the Method IsDeemedPositive.

    For instance, while creating a Ledger, user selects Sundry Debtors as the Group, the Opening Balance entered by the user is defaulted to Debit. Similarly, if the user selects Sundry Creditors as the Group, the Opening Balance entered by the user is defaulted to Credit.

    This happens since the Method IsDeemedPositive is fetched from the selected Group and set within the current Ledger Object context and all the Internal Storages i.e., Opening Balance, Credit Limit, etc. accepts Debit or Credit as per the selected Group.

    But the same behaviour does not work for our UDFs. Hence, to achieve the behaviour, we need to write a User Defined Function and set the UDF Value accordingly.

    Code Snippet:-

    [Line: Final Led Report Alt Credit Limit]

    Fields : Final Led Report IDP, Long Prompt, Final Led Additional Credit Limit
    Local : Field : Long Prompt : Set as : "Addl Credit Limit:"

    [Field: Final Led Report IDP]

    Use : Logical Field
    Storage : IsDeemedPositive
    Set Always : Yes
    Invisible : Yes
    Skip : Yes

    ;; Setting the IsDeemedPositive from the user selected Parent or Group
    Set as : if $$IsSysName:$Parent then No else $IsDeemedPositive:Group:$Parent

    [Field: Final Led Additional Credit Limit]


    Use : Amount Field
    Storage : Final Led Addl CreditLimit
    Format : ("AllSymbols,NoZero,DrCr")
    Width : if $$IsMultiCurrencyOn then @@AmountWidth + 15 else @@AmountWidth
    ;; Triggering the Function to set the Debit or Credit Flag to the UDF Final Led Addl CreditLimit
    Validate : $$IsValidDrCr:$$Value


    [Function: IsValidDrCr]

    Parameter : pValue : Amount

    10: SET TARGET

    20: IF : $IsDeemedPositive

    ;; Setting the UDF Final Led Addl CreditLimit to Debit if the Method IsDeemedPositive is Yes
    30: SET VALUE : Final Led Addl CreditLimit : ##pValue * -1
    40: ELSE:

    ;; Setting the UDF Final Led Addl CreditLimit to Credit (default/as entered) if the Method IsDeemedPositive is No
    50: SET VALUE : Final Led Addl CreditLimit : ##pValue
    60: ENDIF

    ;; Returning Yes to the Attribute Validate to continue to the next Field.
    70: RETURN : Yes


    In the above code snippet, we are using Function IsValidDrCr to check the value of Method IsDeemedPositive and set the UDF Value Final Led Addl CreditLimit to either Debit or Credit as per the value of the Method IsDeemedPositive.
     
    Pritam Krishna likes this.


Share This Page