This knowledge base article will assist developers on how to create User-Defined Tables (UDTs) and User-Defined Fields (UDFs) using the iVend Retail API and the iVend Retail User Interface (UI).
User-Defined Tables (UDTs) are custom tables created using the iVend Retail Extensibility Framework to fulfill various business driven requirements.
Developers can create UDT when they require completely new structures to suit business needs.
UDFs are custom fields that developers can create when they require additional fields in existing forms due the existing fields that are already available not being sufficient to meet business requirements. UDFs can also be created in UDTs.
Developers can create UDTs and UDFs through the iVend Retail User Interface,
Follow these steps to create UDTs and UDFs in iVend using the UI:
1. Open the iVend Management Console.
2. Go to: Administration > Application Setup > User Defined Fields.
3. Click the [F3 New] button, which will open the User Defined Object screen.
4. Now select Custom from the Object Type list drop down.
Selecting Custom allows the user to create UDTs and UDFs. If the requirement is only to create UDFs in an existing table then select an appropriate existing Object from the Object Type list.
1. Enter a business driven values and requirements in the Name, Description and Is History Tracked field respectively.
2. Once all details have been entered as needed, click the [Ok] button to save the changes made.
Refer to the following screen images that illustrate more fully the steps required for creating UDTs and UDFs:
Figure 1 User Defined Object
Figure 2 Creating UDT
Figure 3 Detailed UDT Information
Figure 4 User Defined Valid Values
iVend Retail version 6.6/ 6.5 and above of Extensibility enables developers to create UDTs and UDFs using iVend Retail 6.6/ 6.5 APIs.
The following sample code can be used to create UDTs and UDFs using the iVend Retail 6.6/ 6.5 APIs:
private void CreateUDT()
{
try
{
iVendAPI.IntegrationServiceClient obj = new iVendAPI.IntegrationServiceClient();
iVendAPI.UserDefinedTable sampleUDT = new iVendAPI.UserDefinedTable();
sampleUDT.TableName = "SampleUDT";
sampleUDT.Description = "UDTSample desc";
sampleUDT.IsHistoryTracked = true;
sampleUDT.UserDefinedObjectType = iVendAPI.UserDefinedObjectType.Custom;
iVendAPI.UserDefinedFieldsDetails[] userdefinedfields = new iVendAPI.UserDefinedFieldsDetails[2];
UserDefinedFieldsDetails userdefinedfield1 = new UserDefinedFieldsDetails();
userdefinedfield1.FieldName = "Code";
userdefinedfield1.DataType = UserDefinedFieldDataType.String;
userdefinedfield1.DataLength = 100;
userdefinedfield1.Description = "Code Description";
userdefinedfield1.DisplayOnly = false;
userdefinedfield1.IsMandatory = false;
userdefinedfield1.IsSearchable = false;
userdefinedfield1.ShowInResults = false;
userdefinedfields[0] = userdefinedfield1;
sampleUDT.UserDefinedFieldsDetails = userdefinedfields;
UserDefinedTable result = obj.CreateUserDefinedField(sampleUDT);
if (result.Message != "Success")
{
MessageBox.Show("Error :" + result.Message);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
Creating a UDTs and UDFs Using the Add-on Framework
The following sample code can be used to assist developers with creating UDTs and UDFs using the Add-on Framework:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CXS.Retail.Extensibility;
using CXS.Framework.Core;
using System.Windows.Forms;
namespace SampleAddOnForUDT
{
//Details about Add on
public class iVendAddOn:BasePlugin
{
UserDefinedTable m_SampleTable;
public override string CompanyName
{
get { return "Company Name"; }
}
public override string Description
{
get { return "Sample Add-on for UDT and UDF"; }
}
public override string Name
{
get { return "TestUDT "; }
}
public override Version VersionInfo
{
get
{
return new Version("1.0.0.0");
}
}
//Create UDT on start of Add on.
public override void Start()
{
base.Start();
CreateUDT();
}
//Create user defined table
private void CreateUDT()
{
// No need to check table name with "u_"
m_SampleTable = UserDefinedTableSubSystem.Instance.Load("SampleTable");
if (m_SampleTable == null)
{
//for creating new UDT
m_SampleTable = new UserDefinedTable();
m_SampleTable.TableName = "SampleTable";
m_SampleTable.Description = "Sample user defined Table";
m_SampleTable.IsHistoryTracked = true;
//for creating fields for user defined table --varchar type
UserDefinedField m_Field1 = m_SampleTable.CreateField();
m_Field1.FieldName = "Name";
m_Field1.Description = "Name of sample item";
m_Field1.DataType = UserDefinedFieldDataType.String;
m_Field1.DataLength = 50;
m_SampleTable.AddField(m_Field1);
UserDefinedField m_Field2 = m_SampleTable.CreateField();
m_Field2.FieldName = "Code";
m_Field2.Description = "Code of sample item";
m_Field2.DataType = UserDefinedFieldDataType.Decimal;
m_Field2.DataLength = 10;
m_SampleTable.AddField(m_Field2);
UserDefinedField m_Field3 = m_SampleTable.CreateField();
m_Field3.FieldName = "DateofIssue";
m_Field3.Description = "Issue date of sample item";
m_Field3.DataType = UserDefinedFieldDataType.DateTime;
m_SampleTable.AddField(m_Field3);
CXS.Retail.BusinessLogic.UDFHelperClass.CommitUserDefinedFields(m_SampleTable);
}
else
{
//for adding fields to existing UDT
MessageBox.Show("U_SampleTable UDT already exist.");
//for adding valid values field for custom UDT.
ExtendedBindingList<UserDefinedFieldValidValue> m_UserDefinedFieldValidValueList;
UserDefinedField m_FieldRow = m_SampleTable.Fields.FirstOrDefault(d => d.FieldName == "U_ValidValueFieldColor");
if (m_FieldRow == null)
{
UserDefinedField m_Field4 = m_SampleTable.CreateField();
m_Field4.FieldName = "U_ValidValueFieldColor";
m_Field4.DataType = UserDefinedFieldDataType.ValidValues;
m_UserDefinedFieldValidValueList = m_Field4.UserDefinedFieldValidValueList;
UserDefinedFieldValidValue m_ValidValues1 = UserDefinedFieldValidValueSubSystem.Instance.Create();
m_ValidValues1.Id = "Red";
m_ValidValues1.Description = "Red Description";
m_UserDefinedFieldValidValueList.Add(m_ValidValues1);
UserDefinedFieldValidValue m_ValidValues2 = UserDefinedFieldValidValueSubSystem.Instance.Create();
m_ValidValues2.Id = "Yellow";
m_ValidValues2.Description = "Yellow Description";
m_UserDefinedFieldValidValueList.Add(m_ValidValues2);
UserDefinedFieldValidValue m_ValidValues3 = UserDefinedFieldValidValueSubSystem.Instance.Create();
m_ValidValues3.Id = "Green";
m_ValidValues3.Description = "Green Description";
m_UserDefinedFieldValidValueList.Add(m_ValidValues3);
m_SampleTable.AddField(m_Field4);
m_Field4.IsSearchable = true;
m_Field4.IsMandatory = true;
m_Field4.DisplayOnly = false;
//updating UDT.
CXS.Retail.BusinessLogic.UDFHelperClass.CommitUserDefinedFields(m_SampleTable);
}
else
{
MessageBox.Show(" U_ValidValueFieldColor Field already exist.");
}
}
}
}
}