Add, modify and delete UD table by custom code

Could someone show me an example or tell me where I can find information about adding, modifying and deleting records by code? I need to use the UD02 table to record different analysis by part code and using wizard/table as child does not work for this requirement,

UD02.Key1 = PartNum
UD02.Key2 = AnalysisType
UD02.Key5 = AutoIncrement

I like to use the UpdateExt Method because it does most of the work for you… if the record already exists, it will update the fields you provide. If the record doesnt exist yet, it will add it. You can set RowMod to “D” and it will delete the record.

here is a sample of code. Change the UD Field names to whatever you desire.

using(var svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD12SvcContract>()) {

    //Build and add the UD12 record
    var UD12 = new Ice.Tablesets.UD12Row {
    Company = "MyCompany",
    Key1 = "Some Value",
    Key2 = "AnotherValue",
    Key3 = "",
    Key4 = "",
    Key5 = "",
    };

    UD12.SetUDField<System.String>("UDField1_c", "Some Value");
    UD12.SetUDField<System.String>("UDField2_c", "Some Valueb");
    UD12.SetUDField<System.String>("UDField3_c", "Some Valuec");
    //to delete the record uncomment this line: //UD12.RowMod = "D";

    ds.UD12.Add(UD12);

    BOUpdErrorTableset boUpdateErrors = svc.UpdateExt(ref ds, false, true, out errorOccurred);

}
2 Likes

Thank you very much,

When I execute the code I get this error, I already added the dlls but it still shows the error:

The type or namespace name ‘Assemblies’ does not exist in the namespace ‘Ice’ (are you missing an assembly reference?)

1 Like

I couldn’t get it to work, what worked for me was doing it separately with BPM:

//Modifying:
using (var txScope = IceContext.CreateDefaultTransactionScope())
{

foreach(var ShipVia in (from row in Db.ShipVia.With(LockHint.UpdLock) where
row.Company == Session.CompanyID &&
row.ShipViaCode == “UPS”
select row))
{
ShipVia.WebDesc = “”;
}
Db.Validate();
txScope.Complete();
}

// Deleting
using (var txScope = IceContext.CreateDefaultTransactionScope())
{

foreach(var ShipVia in (from row in Db.ShipVia.With(LockHint.UpdLock) where
row.Company == Session.CompanyID &&
row.ShipViaCode == “UPS”
select row))
{
Db.ShipVia.Delete(ShipVia);
}
Db.Validate();
txScope.Complete();
}

//Inserting
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
ShipVia newRow = new ShipVia();
Db.ShipVia.Insert(newRow);
newRow.Company = Session.CompanyID;
newRow.ShipViaCode = “SVC”;
newRow.Description “My Ship Via”;
Db.Validate();
txScope.Complete();
}