cancel
Showing results for 
Search instead for 
Did you mean: 

Update and remove record from UDO using DI API

former_member275826
Participant
0 Kudos

Hi all,

I have document UDO with Document and document LineTable (For Eg: [@OPRD] AND [@PRD1])

I have successfully added the record in UDO using DI API.

But how to update and remove record using DI API.

Please give me some suggestion.

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor

Hi Pravin,

User the GeneralService.

(Remove)

Dim oGeneralService As SAPbobsCOM.GeneralService
Dim oGeneralParams As SAPbobsCOM.GeneralDataParams

Dim sCmp As SAPbobsCOM.CompanyService
sCmp = oCompany.GetCompanyService

'Get a handle to the SM_MOR UDO
oGeneralService = sCmp.GetGeneralService("SM_MOR")

'Delete UDO record
oGeneralParams = oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)
oGeneralParams.SetProperty("DocEntry", "2")
oGeneralService.Delete(oGeneralParams)

(Update)

Dim oGeneralService As SAPbobsCOM.GeneralService
Dim oGeneralData As SAPbobsCOM.GeneralData
Dim oGeneralParams As SAPbobsCOM.GeneralDataParams

Dim sCmp As SAPbobsCOM.CompanyService
sCmp = oCompany.GetCompanyService

'Get a handle to the SM_MOR UDO
oGeneralService = sCmp.GetGeneralService("SM_MOR")

'Get UDO record
oGeneralParams = oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)
oGeneralParams.SetProperty("DocEntry", "2")
oGeneralData = oGeneralService.GetByParams(oGeneralParams)

'Update UDO record
oGeneralData.SetProperty("U_Room", "2")
oGeneralData.SetProperty("U_Price", "40")
oGeneralData.SetProperty("U_Name", "Guy")
oGeneralService.Update(oGeneralData)

More info is in the SDK Help Center (type GeneralService in the search box).


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

former_member275826
Participant
0 Kudos

Thanx Pedro for your reply.

Please help me in removing particular row of child table.

  SAPbobsCOM.Recordset orec;

                        SAPbobsCOM.GeneralService oGeneralService = null;

                        SAPbobsCOM.GeneralData oGeneralData = null;

                        SAPbobsCOM.CompanyService oCompanyService = null;

                        SAPbobsCOM.GeneralDataCollection oDocLinesCollection;

                        SAPbobsCOM.GeneralData oDocLineGeneralData;

                        oCompanyService = globals_Renamed.oCompany.GetCompanyService();

                        oGeneralService = oCompanyService.GetGeneralService("PRJEST");

                        SAPbobsCOM.GeneralDataParams oGeneralParams;

                        oGeneralData = ((SAPbobsCOM.GeneralData)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData)));

                        oGeneralParams = oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);

                        oGeneralParams.SetProperty("DocEntry", DocEntry);

                        oGeneralData = oGeneralService.GetByParams(oGeneralParams);

                        oDocLineGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);

                        oDocLinesCollection = oDocLineGeneralData.Child("PRJEST1");

                        oDocLinesCollection.Remove(oDAL.EditRowNo);

                        oGeneralService.Update(oGeneralData);

My code is giving me error.

Invalid row Number

pedro_magueija
Active Contributor
0 Kudos

Hi Pravin,

The documentation is unclear about the index type (0-based or something else). Check what value does oDAL.EditRowNo contain at the time that the Remove is called. It might be off range.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

HI PRAVIN  TRY THIS ONE YOU CAN GET AN IDEA...

http://scn.sap.com/thread/3353243

former_member275826
Participant
0 Kudos

Thanx Pedro and srivnivas for ur replies.

Pedro,

ODAL.RowNo is global variable which gives me LineID of the detail table

Srinivas,

I have already referred this link bt it is not working for me.

pedro_magueija
Active Contributor
0 Kudos

Hi Pravin,

The Remove method takes the index of the line on the collection. You should check where the line that you want to delete is in the collection, then use that index with Remove.

oDocLinesCollection.Remove(2); // would the delete the second (or third if the index is 0-based) row of the collection

That does not mean the LineId is 2. You can have a line with ID 2 and be the first one in the collection, if the others have previously been deleted.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (2)

Answers (2)

ens_
Active Participant

Thanks Pedro, it worked. It appears that i did not include the Delete upon registering, to avoid having the user messing around with data. Code Worked.

C# code based on Pedro's Post:

SAPbobsCOM.GeneralService oGeneralService;

                SAPbobsCOM.GeneralDataParams oGeneralParams;

                SAPbobsCOM.CompanyService sCmp;

                sCmp = Globals.oCompany.GetCompanyService();

                //Get a handle to the SM_MOR UDO 

                oGeneralService = sCmp.GetGeneralService("ENTER YOUR UDO ID");

                //Delete UDO record 

                oGeneralParams = (SAPbobsCOM.GeneralDataParams)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);

                oGeneralParams.SetProperty("DocEntry", "2"); //← Deleting 2nd record

                oGeneralService.Delete(oGeneralParams);

ens_
Active Participant
0 Kudos
pedro_magueija
Active Contributor
0 Kudos

Hi Varnavas,

Make sure your UDO has the Delete ability selected. When registering the UDO you can select whether it supports it or not.

That might be the issue.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn