cancel
Showing results for 
Search instead for 
Did you mean: 

How to create matrix style UDO by C# code in sap b1

former_member416544
Participant
0 Kudos

Hi Experts,

I want to add a user-defined object(UDO) as a matrix style using C# code(not a manually).

Could you please someone suggest any reference code in this?

NOTE: Not a manually, via C# code throw only.

Thanks,

Chenna

former_member416544
Participant
0 Kudos

Hi ankit.chauhan1

I have tried with below mentioned code, but Registered UDO created as Header line style only. But I'm looking for Matrix style default form.

Please have a look at the below code

private void RegisterMatrixStyleUDO()
        {
       SAPbobsCOM.UserObjectsMD oUserObjectMD = null;
       SAPbobsCOM.UserObjectMD_FindColumns oUDOFind = null;
       SAPbobsCOM.UserObjectMD_FormColumns oUDOForm = null;
       SAPbobsCOM.UserObjectMD_EnhancedFormColumns oUDOEnhancedForm = null;
      GC.Collect();
 oUserObjectMD = SBO_Company.GetBusinessObject(BoObjectTypes.oUserObjectsMD) as UserObjectsMD;
            oUDOFind = oUserObjectMD.FindColumns;
            oUDOForm = oUserObjectMD.FormColumns;
            oUDOEnhancedForm = oUserObjectMD.EnhancedFormColumns;
            var retval = oUserObjectMD.GetByKey("UDOCODE");
            if (!retval)
            {
                oUserObjectMD.Code = "UDOCODE";
                oUserObjectMD.Name = "NAME";
                oUserObjectMD.TableName = "UDOTableName";
        oUserObjectMD.ObjectType = SAPbobsCOM.BoUDOObjType.boud_MasterData;
                oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanLog = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tNO;
         oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.MenuItem = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.EnableEnhancedForm = BoYesNoEnum.tYES;
                oUserObjectMD.MenuCaption = "Menu Caption";
                oUserObjectMD.FatherMenuID = 48896;
                oUserObjectMD.MenuUID = "UDOMenuUID";
                oUserObjectMD.Position = 5;


                // ==================================
                oUDOFind.ColumnAlias = "Code";
                oUDOFind.ColumnDescription = "Code";
                oUDOFind.Add();
                oUDOFind.ColumnAlias = "Name";
                oUDOFind.ColumnDescription = "Name";
                oUDOFind.Add();
                //========================================

                //=========================================
                oUDOForm.FormColumnAlias = "Code";
                oUDOForm.FormColumnDescription = "Code";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();

                oUDOForm.FormColumnAlias = "U_FirstName";
                oUDOForm.FormColumnDescription = "U_First Name";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();

                oUDOForm.FormColumnAlias = "U_Email";
                oUDOForm.FormColumnDescription = "Email";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();

                //=========================================

                oUDOEnhancedForm.ColumnAlias = "Code";
                oUDOEnhancedForm.ColumnDescription = "Code";
               oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 1;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Editable = BoYesNoEnum.tYES;
                oUDOEnhancedForm.Add();

                oUDOEnhancedForm.ColumnAlias = "U_FirstName";
                oUDOEnhancedForm.ColumnDescription = "First Name";
               oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 2;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Add();

                oUDOEnhancedForm.ColumnAlias = "U_Email";
                oUDOEnhancedForm.ColumnDescription = "Email";
               oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.Editable = BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 3;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Editable = BoYesNoEnum.tYES;
                oUDOEnhancedForm.Add();

                if (!retval)
                {
                    if ((oUserObjectMD.Add() != 0))
                    {
                     int transTemp4 = System.Convert.ToInt32(lErrCode);
                     SBO_Company.GetLastError(out transTemp4, out sErrMsg)
Interaction.MsgBox(sErrMsg, (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
                    }
                    else
                    {
                    }
                }
            }
            Marshal.ReleaseComObject(oUserObjectMD);
        }<br> 

If I'm missing anything please suggest me. Could you please help me with this question.

Thanks,

former_member416544
Participant
0 Kudos

Hi ankit.chauhan1,

May I know, is it possible can we create Matrix-style default UDO form via code throw?.

If yes, could you please someone suggest the steps.

Thanks,

Chenna.

.

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Chenna Gadicherla,

The below code is working fine for me. You can give it a try and let me know:

SAPbobsCOM.UserObjectsMD oUserObjectMD = null;
            SAPbobsCOM.UserObjectMD_FindColumns oUDOFind = null;
            SAPbobsCOM.UserObjectMD_FormColumns oUDOForm = null;
            SAPbobsCOM.UserObjectMD_EnhancedFormColumns oUDOEnhancedForm = null;
            GC.Collect();
            oUserObjectMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD) as SAPbobsCOM.UserObjectsMD;
            oUDOFind = oUserObjectMD.FindColumns;
            oUDOForm = oUserObjectMD.FormColumns;
            oUDOEnhancedForm = oUserObjectMD.EnhancedFormColumns;
            var retval = oUserObjectMD.GetByKey("UDOCODE");
            if (!retval)
            {
                oUserObjectMD.Code = "UDOCODE";
                oUserObjectMD.Name = "NAME";
                oUserObjectMD.TableName = "UDOTABLE";
                oUserObjectMD.ObjectType = SAPbobsCOM.BoUDOObjType.boud_MasterData;
                oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanLog = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.MenuItem = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.EnableEnhancedForm = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.MenuCaption = "Menu Caption";
                oUserObjectMD.FatherMenuID = 48896;
                oUserObjectMD.MenuUID = "UDOMenuUID";
                oUserObjectMD.Position = 5;




                // ==================================
                oUDOFind.ColumnAlias = "Code";
                oUDOFind.ColumnDescription = "Code";
                oUDOFind.Add();
                oUDOFind.ColumnAlias = "Name";
                oUDOFind.ColumnDescription = "Name";
                oUDOFind.Add();
                //========================================


                //=========================================
                oUDOForm.FormColumnAlias = "Code";
                oUDOForm.FormColumnDescription = "Code";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();


                oUDOForm.FormColumnAlias = "U_FirstName";
                oUDOForm.FormColumnDescription = "U_First Name";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();


                oUDOForm.FormColumnAlias = "U_Email";
                oUDOForm.FormColumnDescription = "Email";
                oUDOForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOForm.Add();


                //=========================================


                oUDOEnhancedForm.ColumnAlias = "Code";
                oUDOEnhancedForm.ColumnDescription = "Code";
                oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 1;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.Add();


                oUDOEnhancedForm.ColumnAlias = "U_FirstName";
                oUDOEnhancedForm.ColumnDescription = "First Name";
                oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 2;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Add();


                oUDOEnhancedForm.ColumnAlias = "U_Email";
                oUDOEnhancedForm.ColumnDescription = "Email";
                oUDOEnhancedForm.ColumnIsUsed = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.ColumnNumber = 3;
                oUDOEnhancedForm.ChildNumber = 1;
                oUDOEnhancedForm.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                oUDOEnhancedForm.Add();


                if (!retval)
                {
                    if ((oUserObjectMD.Add() != 0))
                    {
                        MessageBox.Show(oCompany.GetLastErrorDescription());
                    }
                    else
                    {
                    }
                }
            }

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

former_member416544
Participant
0 Kudos

Hi ANKIT CHAUHAN,

Many thanks for your support, It's working fine for me.

Thanks,

Chenna.

Answers (0)