Agregar Desde DI APi C# DATOS A UDT

Buenos días, me podrían ayudar, quiero ingresar datos desde una Aplicación DI API C# hacia una Tabla Definidas de Usuario, pero de Tipo DOCUMENTO Y FILA DE DOCUMENTO (cabezera detalle).
MI PRIMER INTENTO

SAPbobsCOM.UserTable  oUserTable ;

 oUserTable = oCompany.UserTables.Item("TVL_BONIFICACIO");
                oCompany.StartTransaction();
                oUserTable.UserFields.Fields.Item("U_U_SYP_IDEMP").Value = "C50003";
                oUserTable.UserFields.Fields.Item("U_U_TRA_NOMCHO").Value = "ANDRES";

                oUserTable.Add();

Y ME DA UN ERROR DE (Cannot add rows to a MasterData Type UserTable)

Creo que el erro debe de ser por el Tipo de Tabla Documento.

Cualquier comentario Muchas Gracias

Saludos :slightly_smiling_face:

No puedes usar ese método para agregar valores a una UserTable de tipo de Documento o Datos Daestros. El objeto UserTable solo funcionará para la tabla de tipo “Ningún Objeto”. Esto es una limitación en SAP B1 SDK.

Para hacerlo correctamente, deberás registrar la UDT como UDO y alli usar el Objeto GeneralService:

            SAPbobsCOM.GeneralService oGeneralService = null;
            SAPbobsCOM.GeneralData oGeneralData = null;
            SAPbobsCOM.GeneralDataParams oGeneralParams = null;
            SAPbobsCOM.CompanyService sCmp = null;
            SAPbobsCOM.GeneralData oChild = null;
            SAPbobsCOM.GeneralDataCollection oChildren = null;
            sCmp = eCommon.oCompany.GetCompanyService();
            try
            {
                oGeneralService = sCmp.GetGeneralService("UDOName");
                // Get UDO record
                oGeneralParams = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));
                oGeneralParams.SetProperty("DocEntry", DocEntryOfTheRecordToUpdate);
                oGeneralData = oGeneralService.GetByParams(oGeneralParams);
                // Add lines on UDO Child Table
                oChildren = oGeneralData.Child("ChildTableNameWithout@");
                // Create data for rows in the child table
                oChild = oChildren.Add();
                oChild.SetProperty("colUID", "TEST");
                // Update an existing line
                oChild = oChildren.Item(1);
                oChild.SetProperty("colUID", "TEST");
                //Update the UDO Record
                oGeneralService.Update(oGeneralData);
            }
            catch (Exception ex)
            {
                SBO_Application.MessageBox(ex.Message, 1, "OK", null, null);
            }
        

Saludos :vulcan_salute:

5 Me gusta

Muchas gracias, si tiene razón estaba intentando hacer el ingreso sin Crear el UDO en SAP, Directamente hacia las tablas. por lo que no podía usar Objeto GeneralService.
Un error de principiantes. Saludos y Mil gracias por su Ayuda

1 me gusta

Este tema se cerró automáticamente 7 días después del último post. No se permiten nuevas respuestas.