on 12-13-2016 3:15 PM
Hello.
I need to decide if operate an Add or an Update on an UDO
oCompanyService = oCompany.GetCompanyService();
oGeneralService = oCompanyService.GetGeneralService(MyService);
SAPbobsCOM.GeneralDataParams oGeneralParams = (SAPbobsCOM.GeneralDataParams)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);
oGeneralParams.SetProperty("Code", "Key");
oGeneralData = oGeneralService.GetByParams(oGeneralParams);
bool exist = true; // Need to modify
if (exist == true)
{
oGeneralData.SetProperty("Name", descTable);
oGeneralService.Update(oGeneralData);
}
else
{
oGeneralData.SetProperty("Name", descTable);
oGeneralService.Add(oGeneralData);
}
How can I decide if record exist and execute Update or Add?
Hi Riccardo,
First, use the tag SAP Business One SDK as primary tag, with this I believe that you can get more answers.
You can do a select in database using the RecordSet object, and check if your code exists, or use the method getByParams as you did.
A sample with getByParams
oGeneralParams = oSrvGeral.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralDataParams);
oGeneralParams.SetProperty("Code", key);
bool exist = false;
try
{
oGeneralData = oGeneralService .GetByParams(oParamGeral);
if (!string.IsNullOrEmpty(oGeneralData .GetProperty("Code")))
exist = true;
else
oGeneralData = oSrvGeral.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);
}
catch
{
oGeneralData = oSrvGeral.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);
}
Currently in my version, SAP B1 returns an exception when it does not find any register, then we need use the try catch block.
Hope it helps,
Kind Regards,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.