73) How to create a functionaly to select the left right object selection using SysListPanel

  I had a scenario where I need to create the custom left and right movement selection in asset type seltup 


Please review the Requirement  before doing :- 


Step 1 :- To achieve this create a Regular table and drag the fields.


Step 2  :- After that create the class and write the logic in such a way to add and remove from the table 

/// <summary>

/// The <c>AvaSysListPanel_EntAssetObjectTypeCounter</c> class defines a List panel for setting up checklist variable types on asset types.

/// </summary>

public final class AvaSysListPanel_EntAssetObjectTypeVariable extends SysListPanel

{

    EntAssetObjectTypeRecID   refRecId;

    public void addData(container _data)

    {

        int                                            i;

        AvaEntAssetObjectTypeVariableTypeAssociation   relation;

    //

        for (i = 1; i <= conlen(_data); i++)

        {

            relation.ObjectType        = refRecId;

            relation.ChecklistVariable = conpeek(_data, i);

    

            if (relation.validateWrite())

            {

                relation.insert();

            }

            else

            {

                throw error(strfmt("@SYS4007721", tablePname(AvaEntAssetObjectTypeVariableTypeAssociation)));

            }

        }

    }


    /// <summary>

    ///  Get the asset counters to be used in the list panel.

    /// </summary>

    /// <returns>Container with the available and selected asset variable.</returns>

    public container getData()

    {

        container     selectedData;

        container     availableData;

        AvaEntAssetObjectTypeVariableTypeAssociation    relation;

        EntAssetChecklistVariable variableType;

    

        while select TableId from relation

            where relation.ObjectType == refRecId

            join RecId, ChecklistVariableId, Name from variableType  //counterType

                order by ChecklistVariableId

                where variableType.RecId == relation.ChecklistVariable

        {

            selectedData += [[variableType.RecId, variableType.ChecklistVariableId, variableType.Name]];

        }

    

        while select RecId, ChecklistVariableId, Name from variableType

            order by ChecklistVariableId

            notexists join relation

                where relation.ChecklistVariable == variableType.recId &&

                      relation.ObjectType  == refRecId

        {

            availableData += [[variableType.RecId, variableType.ChecklistVariableId, variableType.Name]];

        }

    

        return [availableData, selectedData];

    }


    public int numOfColumns()

    {

        return 2;

    }


    /// <summary>

    /// Parameter, reference to asset type.

    /// </summary>

    /// <param name = "_refRecID">The asset type.</param>

    public void parmObjectTypeRefRecID(EntAssetObjectTypeRecID _refRecID)

    {

        refRecId = _refRecId;

    }


    public void removeData(container _data)

    {

        int                                         i;

        RecId                               VariableTypeRecId;

        AvaEntAssetObjectTypeVariableTypeAssociation    relation;

    

        for (i = 1; i <= conlen(_data); i++)

        {

            ttsBegin;

            VariableTypeRecId = conpeek(_data, i);

            delete_from relation

                where relation.ObjectType  == refRecId &&

                      relation.ChecklistVariable == VariableTypeRecId;

            ttsCommit;

        }

    }


    public boolean validate(anytype _data, AddRemove _addRemove)

    {

        boolean ret = super(_data, _addRemove);

    

        if (_addRemove == addRemove::Add && !refRecId)

        {

            ret = checkFailed("@EnterpriseAssetManagementAppSuite:EntAsset993");

        }

    

        return ret;

    }


    /// <summary>

    /// Creates a new instance of the <c>SysListPanel_EntAssetObjectTypeCounter</c> class.

    /// </summary>

    /// <returns>A new instance of the <c>SysListPanel_EntAssetObjectTypeCounter</c> class.</returns>

    public static AvaSysListPanel_EntAssetObjectTypeVariable construct()

    {

        return new AvaSysListPanel_EntAssetObjectTypeVariable();

    }


   static SysListPanel newForm(FormRun _formRun,

                               int     _parentId)

    {

        AvaSysListPanel_EntAssetObjectTypeVariable sysListPanel = AvaSysListPanel_EntAssetObjectTypeVariable::construct();

    

        sysListPanel.parmFormRun(_formRun);

        sysListPanel.parmParentId(_parentId);

        sysListPanel.parmCaptionSelected("@AvaTransMountain:ChecklistVariableSelected_Label");

        sysListPanel.parmCaptionAvailable("@AvaTransMountain:ChecklistVariableRemaining_Label");

        sysListPanel.parmHasAddAllButton(true);

        sysListPanel.parmHasRemoveAllButton(true);

        sysListPanel.build();


        return sysListPanel;

    }


}

=========================================================================

Step 3 :- Once the logic has been written now its important to initialized the tab create on the group and fill the values of the setup.


This may help to find the group in which we want to initialized the group 

public static class AvaEntAssetObjectTypeFrm_EventHandler

{

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [FormEventHandler(formStr(EntAssetObjectType), FormEventType::Initializing)]

    public static void EntAssetObjectType_OnInitializing(xFormRun sender, FormEventArgs e)

    {

        FormRun                                     element = sender;

        AvaSysListPanel_EntAssetObjectTypeVariable  sysListPanel_Variable;


        sysListPanel_Variable = AvaSysListPanel_EntAssetObjectTypeVariable::newForm(element, element.controlId(formControlStr(EntAssetObjectType, AvaTabPageChecklist)));


        element.parmAvaVariableValue(sysListPanel_Variable);

    }


}


==========================================================================


Step 4 :-  write a logic on the form where we want to see this functionality


[ExtensionOf(formStr(EntAssetObjectType))]

final class AvaEntAssetObjectTypeFrm_Extension

{

    public AvaSysListPanel_EntAssetObjectTypeVariable       sysListPanel_Variable;

    

    public void init()

    {  

       next init();


       this.handleListPanelAccessLevel(this.args() , sysListPanel_Variable);       

       sysListPanel_Variable.init();

      

    }


    public AvaSysListPanel_EntAssetObjectTypeVariable parmAvaVariableValue(AvaSysListPanel_EntAssetObjectTypeVariable _sysListPanel_Variable = sysListPanel_Variable)

    {

        sysListPanel_Variable = _sysListPanel_Variable;

        return  sysListPanel_Variable;

    }








Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++