Thursday, March 24, 2022

Sample Dialog Syntax - 1

 class AffiliationAutoAssignment extends RunBaseBatch

{    

// 1. Class Declaration and Pack variables

    #define.CurrentVersion(1)

    #define.Version1(1)

 

// 2. Dialog Method

/// <summary>

    /// Generate default dialog

    /// </summary>

    /// <returns>default framework dialog validation</returns>

    public Object dialog()

    {

        return super();

    }

// 2. getFromDialog Method

/// <summary>

    /// Get from dialog

    /// </summary>

    /// <returns>boolean</returns>

    public boolean getFromDialog()

    {

        return super();

    }

// 3. Construct Method

/// <summary>

    /// Class Construct method

    /// </summary>

    /// <returns>class AffiliationAutoAssignment </returns>

    public static AffiliationAutoAssignment construct()

    {

        return new AffiliationAutoAssignment();

    }

// 4 Pack method

/// <summary>

    /// Maintains state/version

    /// </summary>

    /// <returns>version and current list</returns>

    public container pack()

    {

        return [#CurrentVersion];

    }

// 5. UnPack method

 /// <summary>

    /// Gets the state/version

    /// </summary>

    /// <param name = "packedClass">container</param>

    /// <returns>true, if it gets previous version</returns>

    public boolean unpack(container packedClass)

    {

        Version version = runbase::getVersion(packedClass);

        ;

        switch (version)

        {

            case #CurrentVersion:

                [version] = packedClass;

                break;

            default:

                return false;

        }

        return true;

    }

// 7. CanRunInNewSession method

/// <summary>

    /// Describes whether the class is designed for execution in a new session.

    /// </summary>

    /// <returns>

    /// true if the class is designed for execution the operation in a new session; otherwise, false.

    /// </returns>

    protected boolean canRunInNewSession()

    {

        return false;

    }

// 8. Run method
/// <summary>
    /// Execute logic to update auto assignment for affiliations based on date range 
    /// </summary>
    public void run()
    {
        System.Exception ex;
        #OCCRetryCount

        try
        {
            this.processData();

            Info("@OperationCompleted");
        }
        catch (Exception::CLRError)
        {
            ex = CLRInterop::getLastException();
            error(ex.ToString());
        }
        catch (Exception::Deadlock)
        {
            retry;
        }
        catch (Exception::UpdateConflict)
        {
            if (appl.ttsLevel() == 0)
            {
                if (xSession::currentRetryCount() >= #RetryNum)
                {
                    throw Exception::UpdateConflictNotRecovered;
                }
                else
                {
                    retry;
                }
            }
            else
            {
                throw Exception::UpdateConflict;
            }
        }
    }

/// <summary>
    /// Entry point to process.
    /// </summary>
    /// <param name = "_args">Args</param>
    public static void main(Args _args)
    {
        AffiliationAutoAssignment affiliationAutoAssignment = new AffiliationAutoAssignment();
        
        if (affiliationAutoAssignment.prompt())
        {
            affiliationAutoAssignment.runOperation();
        }
    }


/// <summary>
    /// set description for batch run
    /// </summary>
    /// <returns>return class description string</returns>
    static ClassDescription description()
    {
        return "UpdateAffiliationAssignments";
    }

Exception Handling for Run Method in Runbase

 public void run()

    {

        System.Exception ex;

        #OCCRetryCount


        try

        {

            this.processData(); //Main logic


            Info("OperationCompleted");

        }

        catch (Exception::CLRError)

        {

            ex = CLRInterop::getLastException();

            error(ex.ToString());

        }

        catch (Exception::Deadlock)

        {

            retry;

        }

        catch (Exception::UpdateConflict)

        {

            if (appl.ttsLevel() == 0)

            {

                if (xSession::currentRetryCount() >= #RetryNum)

                {

                    throw Exception::UpdateConflictNotRecovered;

                }

                else

                {

                    retry;

                }

            }

            else

            {

                throw Exception::UpdateConflict;

            }

        }

    }

Exception Handling for Run Method in RunBase

Use Runbase class instance to get showBatchTab and use below for visiblity

 showBatchTab(True)

or 

showBatchTab(False)

Lookup Code

  

    [FormControlEventHandler(formControlStr(BOMExpandSales, ChargeCode), FormControlEventType::Lookup)]

    public static void ChargeCode_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        Query                   query;

        QueryBuildDataSource    queryBuildDataSource;

        QueryBuildRange         queryBuildRange; 

        SysTableLookup          sysTableLookup;


        sysTableLookup = SysTableLookup::newParameters(tablenum(MarkupTable), sender);

        sysTableLookup.addLookupfield(fieldnum(MarkupTable, MarkupCode), true);

        sysTableLookup.addLookupfield(fieldnum(MarkupTable, Txt));


        query                   = new Query();

        queryBuildDataSource    = query.addDataSource(tablenum(MarkupTable));


        queryBuildRange = queryBuildDataSource.addRange(fieldnum(MarkupTable, ModuleType));

        queryBuildRange.value(queryValue(MarkupModuleType::Cust));

        

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

    }

Standard Batch - adding our variable for Pack/UnPack - 1

1. 

[ExtensionOf(classStr(BomCalcJob))]

final class BomCalcJobBRU_Extension


 #define.CurrentVersion(1)

    #LOCALMACRO.CurrentList

        useCalcDate

    #ENDMACRO

2.

/// <summary>

    /// Maintains state/version

    /// </summary>

    /// <returns>vesion and current list</returns>

    private container currentPack()

    {

        return [#CurrentVersion, #CurrentList];

    }

3.

/// <summary>

    /// Maintains state/version

    /// </summary>

    /// <returns>vesion and current list</returns>

    public container pack()

    {

        container packedClass = next pack();

        return SysPackExtensions::appendExtension(packedClass, classStr(BomCalcJobBRU_Extension), this.currentPack());

    }

4.

 /// <summary>

    /// Gets the state/version

    /// </summary>

    /// <param name = "_packedClass">container</param>

    /// <returns>true, if it gets previous version</returns>

    private boolean currentUnpack(container packedClass)

    {

        Integer version = RunBase::getVersion(packedClass);

        switch (version)

        {

            case #CurrentVersion:

                [version, #currentList] = packedClass;

                break;

            default:

                return false;

        }

        return true;

    }

5.

/// <summary>

    /// Gets the state/version

    /// </summary>

    /// <param name = "_packedClass">container</param>

    /// <returns>true, if it gets previous version</returns>

    public boolean unpack(container _packedClass)

    {

        boolean result = next unpack(_packedClass);


        if (result)

        {

            container currentState = SysPackExtensions::findExtension(_packedClass, classStr(BomCalcJobBRU_Extension));

            //Also unpack the extension

            if (!this.currentUnpack(currentState))

            {

                result = false;

            }

        }


        return result;

    }

Update existing report logic in Process Record

 // <summary>

    ///  Post event handler for processReport method.

    /// </summary>

    /// <param name="args">The arguments</param>

    [PostHandlerFor(classStr(AssetInventoryWorkSheetDP), methodStr(AssetInventoryWorkSheetDP, processReport))]

    public static void AssetInventoryWorkSheetDP_Post_processReport(XppPrePostArgs args)

    {

//1. Get the DP class buffer using args.getThis(). 

//2. Get the temporary table variable using get method

        AssetInventoryWorkSheetDP   assetInventoryWorkSheetDP       = args.getThis() as AssetInventoryWorkSheetDP;

        AssetTmpInventoryWorkSheet  assetTmpInventoryWorkSheetLoc   = assetInventoryWorkSheetDP.getAssetTmpPhysicalInventory();

        AssetTable                  assetTable;


        ttsbegin;

        while select forupdate assetTmpInventoryWorkSheetLoc

            join Barcode, RecId from assetTable

                where assetTable.AssetId == assetTmpInventoryWorkSheetLoc.AssetId

        {

            AssetImage      assetImage      = AssetImage::findForAsset(assetTable.RecId);

            AssetSumCalc    assetSumCalc    = AssetSumCalc_Trans::newAssetYear(

                                            assetTmpInventoryWorkSheetLoc.AssetId,

                                            assetTmpInventoryWorkSheetLoc.BookId);


            assetTmpInventoryWorkSheetLoc.Barcode        = assetTable.Barcode;

            assetTmpInventoryWorkSheetLoc.NetBookValue   = assetSumCalc.netBookValue();

            assetTmpInventoryWorkSheetLoc.Image          = assetImage.Image;


            if (assetImage.RecId)

            {

                assetTmpInventoryWorkSheetLoc.ImageExists    = true;

            }

            else

            {

                assetTmpInventoryWorkSheetLoc.ImageExists    = false;

            }


            assetTmpInventoryWorkSheetLoc.update();

        }

        ttscommit;

    }

Num2Str - Number to String

 str num2Str(   real number,    int character,    int decimals,    int separator1,    int separator2)


Possible enumeration values for the separator1:

  • 1 – point (.)
  • 2 – comma (,)

Possible values for the separator2 :

  • 0 – no thousands separator
  • 1 – point (.)
  • 2 – comma (,)
  • 3 – space ( )
ParameterDescription
numberThe real number to convert to a string.
characterThe minimum number of characters required in the text.
decimalsThe required number of decimal places.
separator1A DecimalSeparator enumeration value.
separator2A ThousandSeparator enumeration value.

Sample Dialog Syntax - 1

 class AffiliationAutoAssignment extends RunBaseBatch {     // 1. Class Declaration and Pack variables     #define.CurrentVersion(1)     #de...