I’m working on a uBAQ that’s linked to OrderDtl. I need the ability to add new, update existing, and as a bonus delete rows in the UD table. Another challenge I haven’t even got too yet is that multiple UD rows can be related to one OrderDtl row.
I got the code working to add a new row but my code on updating isn’t working. The GetByID is returning the row I want to update. Is there a restriction from using the same BO for multiple calls?
Anyway here is the code.
var resultQuery = queryResultDataset.Results.Where(row => !string.IsNullOrEmpty(row.RowMod) && row.RowMod != "P");
foreach (var ttResult in resultQuery)
{
//Call the UD10SvcContract and assign it to udBO. udBO will automatically be disposed of after
//exiting the using statement, so no need to do any cleanup
using (var udBO = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db))
{
//Get a new UD10 Tableset. Make sure to include using Ice.Tablesets; in the usings area
UD10Tableset udTS = new UD10Tableset();
// Get a new, empty UD10 Row
udBO.GetaNewUD10(ref udTS);
// Get the first row from the UD01DataSet, if it exists
var udRow = (from ud10 in udTS.UD10 select ud10).FirstOrDefault();
// Show MsgBox - DEBUG
string body = "1- UD10 RowMod: " + udRow.RowMod + " / ttResult.RowMod: " + ttResult.RowMod +" "+ ttResult.UD10_Key5.Length.ToString();
this.PublishInfoMessage(body, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"FirstVar","SecondVar");
//Set new UD10 row
if(udRow != null && ttResult.UD10_Key5.Length == 0)
{
//generated new GUID
var nguid = Guid.NewGuid().ToString();
//Update fields
udRow.Company = Session.CompanyID;
udRow.Key1 = "TextTag";
udRow.Key2 = ttResult.OrderDtl_OrderNum.ToString();
udRow.Key3 = ttResult.OrderDtl_OrderLine.ToString();
udRow.Key4 = "";
udRow.Key5 = nguid;
udRow.Character01 = ttResult.UD10_Character01;
//Commit new record
udBO.Update(ref udTS);
}
}
//update UD10 row
if(ttResult.UD10_Key5.Length > 0)
{
//new UD10SvcContract
using (var udBO2 = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db))
{
//New UD10Tableset
UD10Tableset udTS2 = new UD10Tableset();
//Set vars and GetByID
string udkey1 = "TextTag";
string udkey2 = ttResult.OrderDtl_OrderNum.ToString();
string udkey3 = ttResult.OrderDtl_OrderLine.ToString();
string udkey4 = "";
string udkey5 = ttResult.UD10_Key5;
udBO2.GetByID(udkey1, udkey2, udkey3, udkey4, udkey5);
//Get the row form the dataset
var udRow2 = (from ud10 in udTS2.UD10 select ud10).FirstOrDefault();
string body2 = "2a ";
this.PublishInfoMessage(body2, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"FirstVar","SecondVar");
if (udRow2 != null)
{
string body2b = "2b " + udkey1 +" "+ udkey2+" "+ udkey3+" "+ udkey4+" "+ udkey5;
this.PublishInfoMessage(body2b, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"FirstVar","SecondVar");
udRow2.Character01 = ttResult.UD10_Character01;
udBO2.Update(ref udTS2);
}
}
}
}
Hmm, possible I guess. I’m only seeing my debug messages once when I usually see them multiple times if it loops. I never see “2b” because of the null.
I would do this by using UpdateExt then you don’t have to get the record, just set the keys and it will be added or updated and if you set a RowMod of D it will be deleted.
Thanks @gpayne, @timshuwy’s code does look nice and clean but there is some declarations missing form his example from how I’m reading the errors correclty.
CS0103 - The name ‘ds’ does not exist in the current context
CS0103 - The name ‘errorOccurred’ does not exist in the current context
Thanks, this is working with my initial posted code. Would like to support deletion too so going to beat on Tim’s code a bit before marking solution and posting code.
I have used UpdateEXT for deletion as well… I was told that it may not work in all instances, but it did in the UD Table I was working with. All you do is set teh RowMod to “D” in addition to all the indexes.
Closer! What reference does UpdExtUD10Tableset need? I tried Ice.Tablesets but the error remains. Do I need to add another assembly than Ice.Contracts.BO.UD10 too?
CS1061 ‘UpdExtUD10Tableset’ does not contain a definition for ‘udRow2’ and no accessible extension method ‘udRow2’ accepting a first argument of type ‘UpdExtUD10Tableset’ could be found (are you missing a using directive or an assembly reference?)
That is something from your original code that is not defined now. If you want to post where is is now, I will throw it into a UD10 Ubaq and see if I can see the issue.
I was about to start Friday drinking like Kevin since in my system UD10 was giving me a message that I had to fill out all of the fields and all I had done was change my UD03 to UD10 to match yours. I changed it to UD29 and it worked. Anyway, this routine does what I believe you want, but if I set RowMod to D it removed it from the Dataset, but not the Db.
I am not sure why you are setting Key5 to a guid when the record will get a unique SysRowID when it is made, but I did that also.
Thanks! This UD table it being used for a customization that ties a OrderDtl to possibly many UD10 rows so I was using the Key5 guid to ensure no duplicates. If I don’t need it then even better.