on 09-08-2008 10:59 AM
Hey,
I have a small question.
I would like to update an UDF by code. I looked into it already but i can't manage to update it.
How do i get the FieldID of a UDF? I do it by walking through a DataTable but it's very slow. Is there any other way?
Can someone show me a little code snippet?
Gr, Jeroen Nijhuis
Hi David,
Can other installed and active addons cause the problem?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I justed wanted to thank david for helping me out personally! Great thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I should email you the source of my add-on..
If you're not willing to place your emailaddress at the forums, you can contact me on my emailaddress at my business card.
I really appreciate your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I really checked my code twice and very accurate,
and i can't find any other bobsCOM object that is not nulled or not being collected. The weird thing is also that I do not use the same com object anywhere else in the code... It's the first time im using it..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jeroen,
something in a another procedure locks the adding process - that's for sure.
no recordset and/or another object is allowed to "access" the udf tables at the moment when you add fields/tables.
this rules is for every function, not only the function you add the code !
and the object destroying from the forum friends above is correct
lg David
I checked the full code and I cannot find any other object that doesnt get nulled...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, ok guys, please help me out.. I still get the error, while i am clearing all other com objects.. please have a look at the full method of code..
if(pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED &&
pVal.ItemUID == "1" &&
!pVal.BeforeAction &&
pVal.FormUID == "e_Setup")
{
SAPbobsCOM.Recordset rs = null;
SAPbobsCOM.UserFieldsMD umd = null;
try
{
SAPbouiCOM.Form frm = (SAPbouiCOM.Form)SBO_Application.Forms.Item(FormUID);
SAPbouiCOM.DataTable dt = (SAPbouiCOM.DataTable)frm.DataSources.DataTables.Item("SetupValues");
SAPbouiCOM.ComboBox cmb_lPrint = (SAPbouiCOM.ComboBox)frm.Items.Item("cmb_lPrint").Specific;
SAPbouiCOM.ComboBox cmb_aLev = (SAPbouiCOM.ComboBox)frm.Items.Item("cmb_aLev").Specific;
SAPbouiCOM.ComboBox cmb_aRMA = (SAPbouiCOM.ComboBox)frm.Items.Item("cmb_aRMA").Specific;
SAPbouiCOM.ComboBox cmb_aGov = (SAPbouiCOM.ComboBox)frm.Items.Item("cmb_aGov").Specific;
SAPbouiCOM.ComboBox cmb_sMail = (SAPbouiCOM.ComboBox)frm.Items.Item("cmb_sMail").Specific;
SAPbouiCOM.EditText internMail = (SAPbouiCOM.EditText)frm.Items.Item("edt_mAdres").Specific;
if (cmb_sMail.Selected.Value == "0" | cmb_sMail.Selected.Value == "3" && internMail.Value == "")
{
SBO_Application.MessageBox("U dient een emailadres op te geven", 0, "Ok", "", "");
frm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;
}
else
{
dt.Columns.Item("U_PrintLbl").Cells.Item(0).Value = cmb_lPrint.Selected.Value;
dt.Columns.Item("U_Leverin").Cells.Item(0).Value = cmb_aLev.Selected.Value;
dt.Columns.Item("U_RmaReto").Cells.Item(0).Value = cmb_aRMA.Selected.Value;
dt.Columns.Item("U_GoedOntv").Cells.Item(0).Value = cmb_aGov.Selected.Value;
dt.Columns.Item("U_MailNoti").Cells.Item(0).Value = cmb_sMail.Selected.Value;
rs = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
rs.DoQuery("SELECT * FROM [@E_SETUP]");
if (rs.RecordCount > 0)
{
StringBuilder setupQuery = new StringBuilder();
setupQuery.Append("UPDATE [@E_SETUP] SET U_PrintLbl = ");
setupQuery.Append(cmb_lPrint.Selected.Value);
setupQuery.Append(", U_Leverin = ");
setupQuery.Append(cmb_aLev.Selected.Value);
setupQuery.Append(", U_RmaReto = ");
setupQuery.Append(cmb_aRMA.Selected.Value);
setupQuery.Append(", U_GoedOntv = ");
setupQuery.Append(cmb_aGov.Selected.Value);
setupQuery.Append(", U_MailNoti = ");
setupQuery.Append(cmb_sMail.Selected.Value);
setupQuery.Append(", U_InternM = '");
setupQuery.Append(internMail.Value);
setupQuery.Append("' WHERE Name = 'Setup'");
rs.DoQuery(setupQuery.ToString());
}
else
{
StringBuilder setupQuery = new StringBuilder();
setupQuery.Append("INSERT INTO [@E_SETUP] values ('0', 'Setup','");
setupQuery.Append(cmb_lPrint.Selected.Value);
setupQuery.Append("','");
setupQuery.Append(cmb_aLev.Selected.Value);
setupQuery.Append("','");
setupQuery.Append(cmb_aRMA.Selected.Value);
setupQuery.Append("','");
setupQuery.Append(cmb_aGov.Selected.Value);
setupQuery.Append("','");
setupQuery.Append(cmb_sMail.Selected.Value);
setupQuery.Append("','");
setupQuery.Append(internMail.Value);
setupQuery.Append("')");
rs.DoQuery(setupQuery.ToString());
}
rs.DoQuery("SELECT FieldID FROM CUFD Where AliasID = 'Print' AND TableID = 'ODLN'");
int errCode = 0;
string errMsg = "";
if (rs.RecordCount == 1)
{
umd = (SAPbobsCOM.UserFieldsMD)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
if (umd.GetByKey("ODLN", Convert.ToInt32(rs.Fields.Item("FieldID").Value.ToString())))
{
umd.DefaultValue = cmb_lPrint.Selected.Value;
if (umd.Update() != 0)
{
company.GetLastError(out errCode, out errMsg);
Logger.Write("An error occured while updating Userfields\n" + errMsg, Category.General, Priority.Normal, 0, System.Diagnostics.TraceEventType.Error);
}
}
}
}
}
catch (Exception ex)
{
Logger.Write("An error occured while updating E-Loop preferences\n " + ex, Category.General, Priority.Normal, 0, System.Diagnostics.TraceEventType.Error);
SBO_Application.MessageBox("Fout: De gegevens zijn niet opgeslagen", 0, "Ok", "", "");
}
finally
{
umd = null;
rs = null;
GC.Collect();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It still gives me the same error after applying your code..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just follow what David has said, and in addition if ur trying to update a UDF in a UDT then u can use the following code snippet..
oUt.UserFields.Fields.Item("U_ud").Value = "XXX"
where oUT is a user table object declared as
Dim oUT As SAPbobsCOM.UserTable
Hope it helps,
Vasu Natari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I know how to update a userfield for a document or object..
But what I mean is that I want to edit the UDF itself, like in:
Tools -> Customization Tools -> User-Defined Fields - Management -> "UDF" -> Update
And then edit the default value, only codewise...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I tried your suggestion, and I get to the point to update the userfield, but it gives me the error:
"Ref count for this object is higher then 0"
How do I solve that?
My code:
rs.DoQuery("SELECT FieldID FROM CUFD Where AliasID = 'Print' AND TableID = 'ODLN'");
int errCode = 0;
string errMsg = "";
if (rs.RecordCount == 1)
{
umd = (SAPbobsCOM.UserFieldsMD)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
if (umd.GetByKey("ODLN", Convert.ToInt32(rs.Fields.Item("FieldID").Value.ToString())))
{
umd.DefaultValue = cmb_lPrint.Selected.Value;
if (umd.Update() != 0)
{
company.GetLastError(out errCode, out errMsg);
Logger.Write("An error occured while updating Userfields\n" + errMsg, Category.General, Priority.Normal, 0, System.Diagnostics.TraceEventType.Error);
}
}
}
Hi,
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
rs = Nothing
GC.WaitForPendingFinalizers()
GC.Collect()
try the above code and before using the Record set object as there is a problem with the object ur getting the error.
After use of ur DI objects call Garbage collector and dump the objects.
Hope it helps,
Vasu Natari.
Hi,
Ref count for this object is higher then 0 -- this is related to number of live COM objects.
If there is more than one component alive at same point of time, you will get this error.
I think you are not releasing the objects properly.
Release COM objects(like userfieldsMD,recordSet etc) using
System.Runtime.InteropServices.Marshal.ReleaseComObject(object)
You can search using ur error message. I answered it couple of times
Regards
Vishnu
Hi,
ok - i missunderstood - you want to change the Default Value
use a RecordSet for this that selects from the CUFD table
oRecordSet.DoQuery("select fieldid from CUFD where aliasid='FieldNameWithoutU' and tableid='@table'")
lg David
Edited by: David Nussböck on Sep 8, 2008 12:04 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
7 | |
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.