SAP B1 SDK UI Cheat Sheet using C#

 


  1. Setting CFL value at Header Level in Custom Screen(CFL After Action)


 try

                            {

                                _Form.Freeze(true);

                                SAPbouiCOM.ChooseFromListEvent cflevent = (SAPbouiCOM.ChooseFromListEvent)pVal;

                                SAPbouiCOM.ChooseFromList oCFLEvento = default(SAPbouiCOM.ChooseFromList);

                                string strUid = cflevent.ChooseFromListUID;

                                oCFLEvento = this.Form.ChooseFromLists.Item(strUid);

                                SAPbouiCOM.DataTable oDataTable = cflevent.SelectedObjects;

                                _chooseFromListItem = (SAPbouiCOM.IChooseFromListEvent)pVal;

                                if (_chooseFromListItem.SelectedObjects != null && _Form.Mode != SAPbouiCOM.BoFormMode.fm_FIND_MODE)

                                {

                                    if (pVal.ItemUID == "Item_5")

                                    {

                                        _dbDataSourceMaster.SetValue("U_PSRCD", _dbDataSourceMaster.Offset, _chooseFromListItem.SelectedObjects.GetValue("Code", 0).ToString());

                                    }

                                }


                                _Form.Freeze(false);

                            }

                            catch (Exception ex)

                            {

                                _Form.Freeze(false);

                                Utilities.ShowErrorMessage(ex.Message);

                            }

                            finally

                            {

                                _Form.Freeze(false);

                                if (_Form.Mode == SAPbouiCOM.BoFormMode.fm_OK_MODE)

                                    _Form.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;

                            }


  1. Creating and Initializing Matrix Object

SAPbouiCOM.Matrix oMatrix=(SAPbouiCOM.Matrix)oForm.Items.Item(“mtrix”).Specific;


  1. Creating and Initializing Column Object

SAPbouiCOM.Column _Col=(SAPbouiCOM.Column)oMatrix.Columns.Item(“ColItemCode”);


  1. Creating and Initializing EditText Object

SAPbouiCOM.EditText _Edit=(SAPbouiCOM.EditText)oForm.Items.Item(“etCardCode”).Specific;


  1. Creating and Initializing Combo Box Object

SAPbouiCOM.ComboBox _oComboBox=(SAPbouiCOM.ComboBox)oForm.Items.Item(“cbSeries”).Specific;



  1. Applying CFL on EditTextBox


_Edit.ChooseFromListUID=”CFL1”;

_Edit.ChooseFromListAlias=”CardCode”;


  1. Applying CFL on Column

_Col.ChooseFromListUID=”CFL2”;

_Col.ChooseFromListAlias=”ItemCode”;


  1. Applying BrowsBy using Code

oForm.DataBrowser.BrowseBy=”etDocEntry”;


  1. Setting Value to the respective Fields in Custome Screen Via DataSource


  • After CFL Selection on header Level

oDBHeaderDataSource.SetValue(“U_CardCode”,0,CFLEvent.SelectedObjects.GetValue(“CardCode”,0).ToString());


  • After CFL Selection on LineLevel

oMatrix.FlushToDataSource();

oDbLineDataSource.SetValue(“U_ItemCode”,oDbLineDataSource.Offset,CFLEvent.SelectedObjects.GetValue(“ItemCode”,0).ToString());

oMatrix.LoadFromDataSource();


  1.  Click on Header level control using Code

oForm.Items.Item(“etRmrks”).Click(BoCellClickType.ct_Regular);


  1. Creating Linked Button and assigning to Edit Text Box Using Code

oItem=oForm.Items.Item(etCardCode)

oNewItem=oForm.Items.Add(“lnkbtn”,SAPBouiCOM.BoFormItemTypes.it_LINKED_BUTTON);

oNewItem.Left=oItem.Left-12;

oNewItem.Height=oItem.Height;

oNewItem.Width=10;

oNewItem.Top=oItem.Top;

oNewItem.LinkTo=”etCardCode”;

oLinkButton=(SAPbouiCOM.LinkedButton)oForm.Items.Item(“lnkbtn”).Specific;

oLinkButton.LinkedObject=BoLinkedObject.If_BusinessPartner;

oLinkButton.LinkedObjectType=”2”;

oLinkedButton.Item.Visible=true;


  1.  Extending Linked Button in Column Edit text and Assigning Object using Code

_Col=oMatrix.Columns.Add(“colItemCode”,SAPbouiCOM.BoFormItemTypes.it_Linked_Button);

_Col.TitleObject.Caption=”ItemCode”;

_Col.Width=120;

_Col.DataBInd.SetBound(true,”@DEMO_RDR1”,”U_ItemCode”);

_Col.Editable=true;

_Col.Visible=true;

oLinkedButton=_Col.ExtendedObject;

oLinkedButton.LinkedObject=SAPbouiCOM.BoLinkedObject.If_Items;


  1.  Creating and Initializing DBDataSourceObject


SAPbouiCOM.DBDataSource oDbHeaderDataSource=null,oDbLineDataSource=null;

    oDbHeaderDataSource=oForm.DataSources.DBDataSources.Item(@DEMO_ORDR);

oDbLineDataSource=oForm.DataSources.oDbLineDataSource.Item(@DEMO_RDR1);


  1. Selecting Form PaneLevel After Item Pressed Event After Action on Tab/Folder

if(pVal.EventType==SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)

{

if(pVal.ItemUID==”Tab_0”)

{

oForm.PaneLevel=1;

}

if(pVal.ItemUID==”Tab_1”)

{

oForm.PaneLevel=2;

}

}


  1. Basic Validation required on the UserDefined Form

Validation 1- Add new Line on the selection of warehouse in the matrix.

Validation 2- Removing Blank records from matrix before adding the document.

Validation 3- Setting fields editable false in OK mode while navigating the form.

Validation 4- Reloading default value like series and document number in Add Mode.


  1. Get latest DocEntry of recently Added Document using DI API

string  DocEntry=Startup.oCompany.GetNewObjectKey();

  1.  Setting Messing on StatusBar

Startup.oApplication.StatusBar.SetText(“message”,BoMessageTime.bmt_Short,BoStatusBarMessageType.smt_Error);


  1. Release ComObject from System Syntax

System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecordSet);


  1.  Create and Initialize Form Object

SAPbouiCOM.Form oForm=null;

oForm=Startup.oApplication.Forms.GetForm(“DemoFrm”,1);


  1. Adding UserDataSource Using Code


SAPbouiCOM.UserDataSource FromDate=null;


FromDate=oForm.DataSources.UserDataSources.Add(“FromDate”,BoDataType.dt_DATE);

  1. Adding SAP DataTable Using Code and execute Query in Data Table

           SAPbouiCOM.DataTable oDataTable=null;

oDataTable=oForm.DataSources.DataTables.Add(“DataTbl”);

oDataTable.ExecuteQuery(“Select DocNum,CardCode from ORDR Where DocStatus=’O’ “);


  1. Create and Initialize Matrix Column ComboBox

SAPbouiCOM.ComboBox ComboBox=(SAPbouiCOM.ComboBox)oMatrix.Columns.Items(“ColLoc”).Cells.item(pVal.Row).Specific;


  1.  Creating and Initializing Button Combo

SAPbouiCOM.ButtonCombo oButtonCombo=null;

oButtonCombo=()oForm.Items.Item(“btnComboPost”).Specific;

oButtonCombo.ValidValues.Add(“17”,”SalesOrder”);

oButtonCombo.ValidValues.Add(“23”,”SalesQuotation”);

oButtonCombo.ExpandType=BoExpandType.et_DescriptionOnly;


  1. Use of CommonSetting in matrix

oMatrix.CommonSetting.SetRoundBackColor(pVal.Row,System.Drawing.Color.Green.ToArrgb());








  1.  Add New Line on the Selection of Warehouse from CFL

String ItemCode=((SAPbouiCOM.EditText)oMatrix.Columns.Item(“colItemCode”).Cellls.Item(pVal.Row).Specific).Value.ToString();

if(ItemCode!=””)

{

oMatrix.AddRow(1,pVal.Row);

oMatrix.ClearRowData(oMatrix.VisualRowCount);

oMatrix.Columns.Item(“colItemCode”).Cells.Item(oMatrix.RowCount).Click(BoCellClickType.Ct_Regular,0);


}


  1.  Matrix Column cell click in specific row

oMatrix.Columns.Item(“colItemCode”).Cells.Item(pVal.Row).Click(BoCellClickType.Ct_Regular,0);


  1.  Matrix Column SumType Setting

_col.ColumnSetting.SumType=BoColumnSumType.bst_Auto


  1.  Matrix Column setting Value without Cell Validation

oMatrix.SetCellWithoutValidation(pVal.Row,”colItemCode”,”dvnd”);


  1.  Checking Matrix Row Selected

oMatrix.IsRowSelected(pVal.Row);


  1.  Reading LineData from Datasource for specific row

oMatrix.GetLineData(pVal.Row);

double Quantity=Convert.ToDouble(oDbLineDataSource.GetValue(“U_Quantity”,oDbLineDataSource.Offset));


  1.  Setting LineData from Datasource for specific row

double  totalAmt=Quantity*Price;

oDbLineDataSource.SetValue(“U_Quantity”,oDbLineDataSource.Offset,totalAmt.ToString());

oMatrix.SetLineData(pVal.Row);








  1. List of Matrix Properties

  1. List of Form Item Types








  1. List of SAP DataTable Properties



  1.  Properties of User DataSources 








  1. Properties of DBDataSources

  1. Remove Blank Record from Matrix 

private void removeBlankRow()

        {

            _mtMatrix.FlushToDataSource();

            for (int i = _mtMatrix.VisualRowCount - 1; i > 0; i--)

            {

                if (string.IsNullOrWhiteSpace(_dbDataSourceChild.GetValue("U_Cirle", i)) || string.IsNullOrWhiteSpace(_dbDataSourceChild.GetValue("U_StlId", i)))

                {

                    _dbDataSourceChild.RemoveRecord(i);

                }

            }

            _mtMatrix.LoadFromDataSource();

        }

  1.  Applying Filter on CFL data at Before Action at matrix level

private void Filter_SiteID(int rowno)

        {

            _mtMatrix.GetLineData(rowno);

            string Circle = _comboTelecomeCircle.Selected.Description;

            int count = 0;

            string sql = String.Empty;

            string aliasColumn = String.Empty;

            SAPbouiCOM.ChooseFromList oCFLEvento = default(SAPbouiCOM.ChooseFromList);

            SAPbouiCOM.Condition oCon = default(SAPbouiCOM.Condition);

            SAPbouiCOM.Conditions oCons = default(SAPbouiCOM.Conditions);

            oCFLEvento = this._Form.ChooseFromLists.Item("CFL_SID");

            oCFLEvento.SetConditions(null);

            oCons = oCFLEvento.GetConditions();

            oCon = oCons.Add();

            oCon.Alias = "U_TelCrl";

            oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;

            oCon.CondVal = Circle;


            oCFLEvento.SetConditions(oCons);


        }

  1.  Adding CFL of custom screen on SAP standard screen

Utilities.AddChooseFromList(Form.UniqueID, "CFLGE", "CFLFA2", SAPbouiCOM.BoLinkedObject.lf_UserDefinedObject, "CIN_OGAE", "DocEntry", "", SAPbouiCOM.BoConditionOperation.co_EQUAL);

                (Form.Items.Item("EdGENo").Specific).ChooseFromListUID = "CFLGE";

                (Form.Items.Item("EdGENo").Specific).ChooseFromListAlias = "DocEntry";