uBAQ to UD table help

Thanks for the reminder the issue currently is that my GetByID appears to not work I’m getting an null error.

image

Wonder if that is the second time going through the loop. We were getting those errors while looping through a collection and calling a BO.

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.

try this.

udTS2 = udBO2.GetByID(udkey1, udkey2, udkey3, udkey4, udkey5);

1 Like

Or maybe GetByID has a ref to udTS2…

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.

3 Likes

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.

1 Like

Add this at the top EDIT UD10

UpdExtUD10Tableset ds = new UpdExtUD10Tableset();

and this just before the update

bool errorOccurred;
1 Like

I also have mine wrapped in a using at the very top.

using(var UD10Svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db, true))
{

} // last line
1 Like

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.

Sorry I should of posted it. The error is coming on: ds.udRow2.Add(udRow2);

      foreach (var ttResult in resultQuery)
      {  
 
          using (var udBO = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db))
          {
            UD10Tableset udTS = new UD10Tableset();

            udBO.GetaNewUD10(ref udTS);

            var udRow = (from ud10 in udTS.UD10 select ud10).FirstOrDefault(); 
 
            //New UD10 row 
            if(udRow != null && ttResult.UD10_Key5.Length == 0)
            {
                var nguid = Guid.NewGuid().ToString();  

                udRow.Company = Session.CompanyID;
                udRow.Key1 = "ARSLightRepCom";  
                udRow.Key2 = ttResult.OrderDtl_OrderNum.ToString();
                udRow.Key3 = ttResult.OrderDtl_OrderLine.ToString();
                udRow.Key4 = "";
                udRow.Key5 = nguid; 
                udRow.Character01 = ttResult.UD10_Character01;     
                
                udBO.Update(ref udTS);
            }        
          }

          //update UD10 row  
          if(ttResult.UD10_Key5.Length > 0)
          {
          
            using (var svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db))
            {    
              UpdExtUD10Tableset ds = new UpdExtUD10Tableset();
              
              bool errorOccurred;
              
              string udkey1 = "ARSLightRepCom";
              string udkey2 = ttResult.OrderDtl_OrderNum.ToString();
              string udkey3 = ttResult.OrderDtl_OrderLine.ToString();
              string udkey4 = "";
              string udkey5 = ttResult.UD10_Key5;   
              
              var udRow2 = new Ice.Tablesets.UD10Row {
                Company = Session.CompanyID, Key1 = udkey1, Key2 = udkey2, Key3 = udkey3, Key4 = udkey4, Key5 = udkey5,};
   
              udRow2.Character01 = ttResult.UD10_Character01; 
              //udRow2.SetUDField<System.String>("UDField1_c", "Some Value");
              //to delete the record uncomment this line: //UD12.RowMod = "D";
              
              ds.udRow2.Add(udRow2);
              
              BOUpdErrorTableset boUpdateErrors = svc.UpdateExt(ref ds, false, true, out errorOccurred);
            } 
          } 
      } 

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.

/* Create Update UD10 records */
using(var UD10Svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD10SvcContract>(Db, true))
{

UpdExtUD10Tableset UD10ts = new UpdExtUD10Tableset();

Ice.Diagnostics.Log.WriteEntry(" in Update  UD10");


foreach (var ttResult in queryResultDataset.Results.Where(row => !String.IsNullOrEmpty(row.RowMod)).Select(row => row) )
{


Ice.Diagnostics.Log.WriteEntry($"in create UD10 {ttResult.OrderDtl_OrderNum} - {ttResult.OrderDtl_OrderLine}"); /* order/line  */

                    
  
                    if(string.IsNullOrEmpty(ttResult.UD10_Key5))
                    {
                       ttResult.UD10_Key5 = Guid.NewGuid().ToString();
                    }
                    
                
                
                  var UD10 = new Ice.Tablesets.UD10Row
                  {
                    
                    Key1 = "ARSLightRepCom",
                    Key2 = ttResult.OrderDtl_OrderNum.ToString(),
                    Key3 = ttResult.OrderDtl_OrderLine.ToString(),
                    Key4 = "",
                    Key5 = ttResult.UD10_Key5,
                    Company = Session.CompanyID,
                    SysRowID = ttResult.UD10_SysRowID,
                  };
                    
                    
                    UD10.Character01 = ttResult.UD10_Character01; 
     
                    
                    UD10ts.UD10.Add(UD10);
    
     
        bool errorOccurred;
        BOUpdErrorTableset boUpdateErrors = UD10Svc.UpdateExt(ref UD10ts, false,true, out errorOccurred);
   

}
}
1 Like

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.

Is there only one UD10 for each order/line? Or can a detail line have multiple UD10 records?

One OrderDtl line can have many UD10 lines.

I owe you a drink at Insights!

1 Like

Key5 or SysRowID is going to limit that to one checking for length or Empty. What differentiates the UD10 records?

If you added a couple of calculated checkboxes for New and Delete you would know when to generate a new guid or delete the current record.