Passing Dataset to BO

I am creating a Method Directive that is passing a dataset that will sometimes have multiple records, to a BO that does not support multiple records.

I imagine if I can clear my dataset except for the first row, and then pass it, I will be able to loop through until there is nothing left to process.

I was really trying to do this without using the custom code widget. I’m getting stuck on how to only pass a single record to the BO, any thoughts?

Here’s my 2 cents (I am by no means the best resource but here goes):

I would use a foreach loop to go through each “data row” in your data one row at a time, and I would then set the TableSet to this row (the original row and the RowMod=“U” row you have changed, essentially representing the same row), with the necessary changes within your loop, and perform the BO…Update(ref Ts); with each iteration, ensuring you’re not populating a full tableset of multiple updated rows before attempting to feed the Update method on the BO.

Hope this makes sense-- I’ve never encountered that issue before but I have definitely run BO.Update() methods within a foreach loop in this manner.

Here’s an example I have had to use multiple times in our system related to CRM Tasks on Quotes…

tskTs = tsk.GetRows(wc,wctc,0,0,out mp);
  
  if (tskTs.Task.Count() == 1) {
      foreach (var tRow in tskTs.Task.ToList()) {
        var drOrig = tskTs.Task.NewRow();
        BufferCopy.Copy(tRow, drOrig);
        tskTs.Task.Add(drOrig);
        tRow.RowMod = "U";
        tRow.Complete = true;
        tRow.CompleteDate =  DateTime.UtcNow.Date;
        tRow.ChangeDcdUserID = callContextClient.CurrentUserId;
        tsk.Update(ref tskTs);   
    }
  }
  //Dispose of task business object at end of code
  tsk.Dispose();

Note that in this example, my TableSet only ever consisted of 1 row to begin with so I didn’t have to clear the TableSet in the loop-- it didn’t matter for me. In your case you would probably have to query your TableSet rows in a command above the loop to ensure it consists of 1 row (handled by your WhereClause parameter string).

EDIT-- Sorry, just realized in your original post you were trying to accomplish something WITHOUT custom code-- my bad. Hope this might somehow help someone anyways.

Thank you.

I am actually trying to perform some WIP-WIP moves based on jobs that share an internal batch Id that lives in JobHead.UserChar1

I am (maybe incorrectly) assuming I need to use the IssueReturn → PerformMaterialMove BO, so I am not using Update or UpdateExt.

1 Like

Understood-- the underlying concept here is what I hoped to get across which is setting your dataset to 1 row before you attempt to pass it to the BO. Generally this can either be done with the WhereClause parameter as you query it, OR once you’ve queried it you can enumerate through the data one row at a time and perform your action within the loop.