02-11-2018 5:51 PM - edited 02-04-2024 3:26 AM
Hi Guys,
I wanna ask about how to create User defined feilds on system form using c# and how to make the add button add all fields at once.
Hi Hassan,
Create User defined feilds on system form using c#.
public void InitDeclareUdfs()
{
CreateUserDefinedField("MyUDFName", "MyUDFDescription", BoFieldTypes.db_Alpha, 100, "OPMG", null, null);
}
private void CreateUserDefinedField(string Name, string Descreption,
BoFieldTypes dataType, int size, string tableName, Dictionary<string,
string> dictionary, string defaultValue = "")
{
GC.Collect();
var SboCompany = ServiceLocator.SboCompany;
var recordset = (Recordset)SboCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
var userField = (UserFieldsMD)SboCompany.GetBusinessObject(BoObjectTypes.oUserFields);
recordset.DoQuery("SELECT FieldId FROM cufd where AliasId ='" + Name + "' and tableid = '" + tableName + "'");
int Count = recordset.RecordCount;
int ufId = 0;
if (Count != 0)
{
ufId = Convert.ToInt32(recordset.Fields.Item(0).Value);
}
Marshal.ReleaseComObject(recordset);
if (Count == 0)
{
userField.TableName = tableName;
userField.Name = Name;
userField.Description = Descreption;
userField.Type = dataType;
var vv = userField.ValidValues;
if (dictionary != null)
{
var valids = new List<string>();
for (int i = 0; i < vv.Count; i++)
{
vv.SetCurrentLine(i);
valids.Add(vv.Value);
}
foreach (var pair in dictionary)
{
if (valids.Contains(pair.Key))
{
continue;
}
userField.ValidValues.Value = pair.Key;
userField.ValidValues.Description = pair.Value;
userField.ValidValues.Add();
}
}
userField.DefaultValue = defaultValue;
if (dataType != BoFieldTypes.db_Numeric)
userField.Size = size;
Marshal.ReleaseComObject(recordset);
if (userField.Add() != 0)
{
//int transTemp4 = System.Convert.ToInt32(lErrCode);
//SboCompany.GetLastError(out transTemp4, out sErrMsg);
//Interaction.MsgBox(sErrMsg, (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
//Application.SBO_Application.SetStatusBarMessage("Error while trying
to add the field [" + Name + " - " + tableName + "] - [" +
Company.GetLastErrorDescription() + "]", BoMessageTime.bmt_Short, true);
}
else
{
//Application.SBO_Application.SetStatusBarMessage("User-defined field
[" + Name + " - " + tableName + "] has been created successfully",
BoMessageTime.bmt_Short, false);
}
Marshal.ReleaseComObject(userField);
}
}
Regards,
Chenna.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
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.