Add Memo Programmatically From Dashboard

Hello All!
I have a dashboard that automatically closes releases, lines, and orders. It does this with a custom code widget in a BPM on a uBAQ with a custom action.

I want to add a memo to the order level any time an order is closed with this program. I performed this action and traced it to figure out which methods to use.

In my custom code, I close an order with this logic. Actually this does a few operations. It can close, and delete releases depending on what is required. It can also close lines and orders. Find my boolean “CloseOrder=True” to see the section that actually closes an order.

CloseCount=0;
DelCount=0;
UpdateCount=0;
RelCount=0;
ManualUp=0;
CloseOrder=false;

// step through each row of results
foreach (var xRow in (from ttResults_Row in queryResultDataset.Results where ttResults_Row.Calculated_CloseRelease == true || ttResults_Row.Calculated_UseGEDate == true ||  ttResults_Row.Calculated_Manual == true select ttResults_Row))
{
  //parse out order, line, rel from calculated field.
  MyOrder = System.Convert.ToInt32(xRow.OrderRel_OrderNum);
  MyLine = System.Convert.ToInt32(xRow.OrderRel_OrderLine);
  MyRel = System.Convert.ToInt32(xRow.Calculated_MinRel);
  //if Calculated_CloseRelease then close the open release
  // We really want to delete these releases as long as they have not been shipped on, and they do not have any jobs created on them, and they are not the only release on a line.
  if (xRow.Calculated_CloseRelease == true)
  {
     
      using (Erp.Contracts.SalesOrderSvcContract soSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
    {   
      Erp.Tables.OrderRel OrderRel;
      var ORel = (from OrderRel_Row in Db.OrderRel
                 where OrderRel_Row.Company == Session.CompanyID && 
                       OrderRel_Row.OrderNum == MyOrder && 
                       OrderRel_Row.OrderLine == MyLine  
                 select OrderRel_Row); //Get the OrderRel record to update...
      if (ORel != null)
      {
        RelCount = ORel.Count();
      }
     if ((xRow.Calculated_Shipped >= 1) || (xRow.Calculated_MinJob != string.Empty || RelCount == 1)) //cant delete release, so close it
     {
       using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
      {
      foreach (var rels in (from rRow in Db.OrderRel where rRow.OrderNum == MyOrder && rRow.OrderLine == MyLine && rRow.OrderRelNum == MyRel select rRow))
       {
        if (rels != null)
        {
         rels.Character01 = BpmFunc.Now() + " System closed release " +  MyRel + " in order " + MyOrder + " on line " +  MyLine + ". " + " Shipped: " + xRow.Calculated_Shipped + " FirstJob: " + xRow.Calculated_MinJob;
         Db.Validate(rels);
         txscope1.Complete();
        }
           }
        }
       soSvc.CloseRelease(MyOrder, MyLine, MyRel);
       soSvc.Update(ref MyVar1);
       CloseCount = CloseCount + 1;
     }
     else // not closing release, so delete it
     {
     //using (Erp.Contracts.SalesOrderSvcContract soSvc =  Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
      {
      SalesOrderTableset SOTS = soSvc.GetByID(MyOrder);  
      var desiredReleases = SOTS.OrderRel.Where(r => r.OrderLine == MyLine && r.OrderRelNum == MyRel); 
      foreach(var rel in desiredReleases)
      {
        rel.RowMod = "D";
        DelCount = DelCount + 1;
      }
      
      soSvc.Update(ref SOTS);
      var openRels = SOTS.OrderRel.Where(r => r.OpenRelease == true); 
      if (openRels.Count() == 0) 
      
      {
        soSvc.CloseOrderLine(MyOrder, MyLine);
        soSvc.Update(ref SOTS);
      }
      var openLines = SOTS.OrderDtl.Where(r => r.OpenLine == true); 
      if (openLines.Count() == 0) 
      
      {
        soSvc.CloseOrder(MyOrder);
        soSvc.Update(ref SOTS);
        CloseOrder=true;
      }
      }
     }
     xRow.Calculated_CloseRelease = false;
     
    } 
  }
  //if Calcualted_UseGEDate then change our date to ge date
  if (xRow.Calculated_UseGEDate == true)
  {
    // check to see if there is a valid date to update to - if not warn the user and uncheck usedate
    if (xRow.Calculated_MinDate == null)
    {
    PublishInfoMessage("There is no CT date for order " + MyOrder + " on line " +  MyLine + " release " + MyRel +  ". Check your selection.", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
    xRow.Calculated_UseGEDate = false;
    }
    else
    {
    MyOrder = xRow.OrderRel_OrderNum;
    MyLine = xRow.OrderRel_OrderLine;
    MyRel = xRow.Calculated_MinRel;
    MyDate = xRow.Calculated_MinDate;
    Erp.Tables.OrderRel OrderRel;
    using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
    {
     foreach (var rel in (from rRow in Db.OrderRel where rRow.OrderNum == MyOrder && rRow.OrderLine == MyLine && rRow.OrderRelNum == MyRel select rRow))
     {
      if (rel != null)
      {
        string DateNew = String.Format("{0:M/d/yyyy}", MyDate);
        string DateOld = String.Format("{0:M/d/yyyy}", rel.ReqDate);
        rel.Character01 =  BpmFunc.Now() + "--- System updated release " +  MyRel + " in order " + MyOrder + " on line " +  MyLine + "." + " Old Date: " + DateOld + " New Date: " + DateNew;
        rel.ReqDate = MyDate;
        rel.NeedByDate = MyDate;
        Db.Validate(rel);
        UpdateCount = UpdateCount + 1;
      }
      txscope1.Complete();
      }
    }
    xRow.Calculated_UseGEDate = false;
    }
  }
  
// all that is left are the manual edits
// For each manual edit, just apply the updated values
if (xRow.Calculated_Manual == true)
  {
     using (Erp.Contracts.SalesOrderSvcContract soSvc =  Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
      {
      SalesOrderTableset SOTS = soSvc.GetByID(MyOrder);  
      var desiredReleases = SOTS.OrderRel.Where(r => r.OrderLine == MyLine && r.OrderRelNum == MyRel); 
      MyDate = xRow.OrderRel_ReqDate;
      foreach(var rel in desiredReleases)
      {
        string DateNew = String.Format("{0:M/d/yyyy}", MyDate);
        string DateOld = String.Format("{0:M/d/yyyy}", rel.ReqDate);
        rel["Character01"] =  BpmFunc.Now() + "--- System manually updated release " +  MyRel + " in order " + MyOrder + " on line " +  MyLine + " Old Date: " + DateOld + " New Date: " + DateNew + " Old Qty: " + Convert.ToInt32(rel.OurReqQty) + " New Qty: " + xRow.OrderRel_OurReqQty;
        rel.ReqDate = MyDate;
        rel.NeedByDate = MyDate;
        rel.OurReqQty = xRow.OrderRel_OurReqQty;
        rel.Make = true;
        rel.RowMod = "U";
        ManualUp=ManualUp+1;
      }
      soSvc.Update(ref SOTS);
      

      
      }
      
  }
}

I used a boolean called CloseOrder set to true if the program decides to close an order. After this custom code executes, I use a Memo.GetNewMemo widget, along with an Update Table by Query and Memo.Update widgets to try to create the details for the new memo. This actually works ok. My only problem is that I don’t know how to get the RelatedToSysRowID field for GetNewMemo. I think this is how it links to the Order number. I have to set this filed when I GetNewMemo. How can I point to the correct Order Number? I used a trace and set key1 to OrderNum and key2 to LineNum, but I can’t figure out how to get that GUID.

I appreciate any ideas. Thanks!
Nate

Can you access the order number at any point before the GetNewMemo widget executes? You could do a getbyid execution for salesorder and then select the sysrowid from that salesorderdataset when setting the values of the getnewmemo widget? Or you could use LINQ and query for it in a custom code widget.

1 Like

This was the part I was missing! Thank you!

Sweet! Please mark the answer if it works for you :slight_smile: