# BPM Data Directive - Custom Code

**URL:** <https://www.epiusers.help/t/bpm-data-directive-custom-code/103896>\
**Category:** Epicor ERP 10\
**Tags:** bpm\
**Created:** [June 11, 2023, 2:59pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896 "2023-06-11T14:59:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 11, 2023, 2:59pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/1 "2023-06-11T14:59:56Z")

</div>

Anyone have an idea why I am receiving the error below?

![image](https://www.epiusers.help/uploads/default/original/3X/a/5/a5d78dea0b87e1def42b1893031620fc81e55a1c.png)

![image](https://www.epiusers.help/uploads/default/original/3X/8/0/80bf3b18eca18e1dce0b8e7a42a498137b56c565.png)

![image](https://www.epiusers.help/uploads/default/original/3X/7/9/79980cbb8db9d97948cd80185dc85c29a2c7485e.png)

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [June 11, 2023, 3:10pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/2 "2023-06-11T15:10:13Z")

</div>

It’s expecting a string and you’re giving it an integer.

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [June 11, 2023, 3:48pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/3 "2023-06-11T15:48:23Z")

</div>

After looking into it, not sure why you are getting that.

Erp.BO.PO.GetByID takes an integer, and you have an integer.

Did you change that variable after creating it?

Try commenting out the code, removing the variable, and save all the way out.  
Then go back and put the variable back in and uncomment the code.

---

<div class="post-metadata">

**Author:** ![gpayne](https://www.epiusers.help/user_avatar/www.epiusers.help/gpayne/32/55751_2.png) [@gpayne](https://www.epiusers.help/u/gpayne)\
**Post date:** [June 12, 2023, 1:21am UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/4 "2023-06-12T01:21:14Z")

</div>

Sometimes implicit casting is dumb. Try putting (int) into the expression for PONum.

---

<div class="post-metadata">

**Author:** ![JasonMcD](https://www.epiusers.help/user_avatar/www.epiusers.help/jasonmcd/32/22326_2.png) [@JasonMcD](https://www.epiusers.help/u/JasonMcD)\
**Post date:** [June 12, 2023, 7:23pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/5 "2023-06-12T19:23:44Z")

</div>

Maybe use a **Long** and not an Int?

---

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 13, 2023, 2:37pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/6 "2023-06-13T14:37:06Z")

</div>

It was not failing on the GetByID method. It was actually failing on this line:

foreach(DataRow dRow in ds.Tables[“PODetail”].Rows)

It is not able to resolve the table name so I changed it to:

foreach(DataRow dRow in ds.Tables[1].Rows)

I’m guessing table 1 is PODetail.

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [June 13, 2023, 2:39pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/7 "2023-06-13T14:39:41Z")

</div>

> [@JeffSanders](#):
>
> It was not failing on the GetByID method. It was actually failing on this line:

🤣 Ahhhh!  
 ![red_herring1](https://www.epiusers.help/uploads/default/original/3X/8/d/8d378717ed36c93fcaa8b3fd67994b4ff05a5b35.png)

---

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 13, 2023, 9:49pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/8 "2023-06-13T21:49:27Z")

</div>

I am trying to use a BPM template example to access XXX\_UD fields which was posted by Brenda on several occasions. There seems to be a parenthesis missing from the template. I’ve got more errors than I can shake a stick at.

```cs
//Erp.Tables.PODetail PODetail;
//Erp.Tables.PODetail_UD PODetail_UD;

foreach(Erp.Bpm.TempTables.ReqDetailTempRow rRow in ttReqDetail)
{
  decimal Qty = Convert.ToDecimal(rRow["Number08"].ToString());
  decimal Width = Convert.ToDecimal(rRow["Number09"].ToString());
  decimal Length = Convert.ToDecimal(rRow["Number10"].ToString());
  decimal Weight = Convert.ToDecimal(rRow["Number20"].ToString());
  string QtyStr = rRow["Character01"].ToString();
  string WidStr = rRow["Character02"].ToString();
  string LenStr = rRow["Character03"].ToString();
  int ReqPONum = Convert.ToInt32(rRow["PONum"].ToString());
  int ReqPOLine = Convert.ToInt32(rRow["POLine"].ToString());
  
  using (var txscope = IceDataContext.CreateDefaultTransactionScope())
  {
    foreach (var PODetail_Recs in (from PODetail_Row in Db.PODetail
    var PODetail_Recs = (from PODetail_Row in Db.PODetail from PODetail_UD_Row in Db.PODetail_UD where PODetail_Row.Company == Session.CompanyID && PODetail_Row.SysRowID == PODetail_UD_Row.ForeignSysRowID && PODetail_Row.PONUM == ReqPONum && PODetail_Row.POLine = ReqPOLine select new { PODetail_Row, PODetail_UD_Row })).FirstOrDefault();
    {
       if (PODetail_Recs != null)
       {
         PODetail_Recs.PODetail_UD_Row.Character01 = QtyStr;
         PODetail_Recs.PODetail_UD_Row.Character02 = WidStr;
         PODetail_Recs.PODetail_UD_Row.Character03 = LenStr;
         PODetail_Recs.PODetail_UD_Row.Number08 = Qty;
         PODetail_Recs.PODetail_UD_Row.Number09 = Width;
         PODetail_Recs.PODetail_UD_Row.Number10 = Length;
         PODetail_Recs.PODetail_UD_Row.Number20 = Weight;
         Db.Validate(PODetail_Recs.PODetail_Row);
         Db.Validate(PODetail_Recs.PODetail_UD_Row);
       }
     } / ***PODetail*** /

     txscope.Complete();
  }  
}

```

Here is the original template:

```cs
//Erp.Tables.XXX XXX;
//Erp.Tables.XXX_UD XXX_UD;

using (var txscope = IceDataContext.CreateDefaultTransactionScope())
{
   foreach (var XXX_Recs in (from XXX_Row in Db.XXX
   var XXX_Recs = (from XXX_Row in Db.XXX
                                 from XXX_UD_Row in Db.XXX_UD
                                 where XXX_Row.Company == Session.CompanyID
                                 && XXX_Row.SysRowID == XXX_UD_Row.ForeignSysRowID
                                 && XXX_Row.YYY == false
                                 select new { XXX_Row, XXX_UD_Row })).FirstOrDefault();
   {
      if (XXX_Recs != null)
      {
         XXX_Recs.XXX_Row.YYY = false;
         XXX_Recs.XXX_UD_Row.YYY = false;
         Db.Validate(XXX_Recs.XXX_Row);
         Db.Validate(XXX_Recs.XXX_UD_Row);
      }
   } / ***XXX*** /
   txscope.Complete();
}

```

The original template looks like there are three opening parenthesis after the foreach statement and there are only two closing parenthesis. Also, it looks like it is defining XXX\_Recs twice. Has anyone successfully used this template?

---

<div class="post-metadata">

**Author:** ![gpayne](https://www.epiusers.help/user_avatar/www.epiusers.help/gpayne/32/55751_2.png) [@gpayne](https://www.epiusers.help/u/gpayne)\
**Post date:** [June 13, 2023, 10:11pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/9 "2023-06-13T22:11:57Z")

</div>

That template was at the beginning of ABL to C#. Things have advanced a ton since then. You don’t reference the UD, it is all handled behind the dbo view.

Something more like from this solution would be used now for writing to the Db. Or use UpdateExt for everything and you can use the objects and never write to the Db.

> [@Set a UD field from an unrelated UD Table](https://www.epiusers.help/t/set-a-ud-field-from-an-unrelated-ud-table/87439/10):
>
> Try this. foreach (var tt in ttUD08.Where(tt =\> tt.Updated() || tt.Added())) { var JobHead = (from jh in Db.JobHead.With(LockHint.UpdLock) where jh.Company == tt.Company && jh.Character01 == tt.Key1 select jh).ToList(); foreach (var x in JobHead) { if(x!=null) { x.SetUDField\<System.Boolean\>("CheckBox05", tt.CheckBox01); Db.Validate(); } } }

Thread on UpdateExt  
[https://www.epiusers.help/t/bpm-best-practice/92146/7](https://www.epiusers.help/t/bpm-best-practice/92146/7)

Where is the data coming from that you want to save in PODetail?

---

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 13, 2023, 10:48pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/10 "2023-06-13T22:48:02Z")

</div>

ReqDetail.

---

<div class="post-metadata">

**Author:** ![gpayne](https://www.epiusers.help/user_avatar/www.epiusers.help/gpayne/32/55751_2.png) [@gpayne](https://www.epiusers.help/u/gpayne)\
**Post date:** [June 13, 2023, 11:43pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/11 "2023-06-13T23:43:56Z")

</div>

I didn’t try to do an UpdateExt example since I am not great at them and I have no data to test with. These are all UD fields and based on what I think I saw they are the same in both files.  
I have only compiled this since I don’t have any Req data.  
Uncomment your fields and I think this should be close.

```auto
/* ReqDetail to PODetail */

foreach (var reqRow in ds.ReqDetail)
{

  var podList = (from podtl in Db.PODetail.With(LockHint.UpdLock) 
      where podtl.Company == reqRow.Company
      && reqRow.PONUM == podtl.PONUM
      && reqRow.ReqLine == podtl.POLine select podtl).ToList();
  
  foreach (var x in podList)
  {
    if(x!=null)
    {
    
        x.SetUDField<System.String>("LineDesc", reqRow.LineDesc);
      /*
        x.SetUDField<System.String>("Character01", reqRow.Character01);
        x.SetUDField<System.String>("Character02", reqRow.Character02);
        x.SetUDField<System.String>("Character03", reqRow.Character03);
        x.SetUDField<System.Decimal>("Number08", reqRow.Number08);
        x.SetUDField<System.Decimal>("Number09", reqRow.Number09);
        x.SetUDField<System.Decimal>("Number10", reqRow.Number10);
        x.SetUDField<System.Decimal>("Number20", reqRow.Number20);
        */
        Db.Validate();
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 14, 2023, 1:31pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/12 "2023-06-14T13:31:54Z")

</div>

This looks much easier to follow. I changed the first foreach statement to use ttReqDetail instead. But it must be causing an invalid cast.

```auto
foreach (var reqRow in ttReqDetail)
{
  var podList = (from podtl in Db.PODetail.With(LockHint.UpdLock) 
      where podtl.Company == reqRow.Company
      && reqRow.PONUM == podtl.PONUM
      && reqRow.ReqLine == podtl.POLine select podtl).ToList();
  
  foreach (var x in podList)
  {
    if(x != null)
    {
        x.SetUDField<System.String>("Character01", reqRow.Character01);
        x.SetUDField<System.String>("Character02", reqRow.Character02);
        x.SetUDField<System.String>("Character03", reqRow.Character03);
        x.SetUDField<System.Decimal>("Number08", reqRow.Number08);
        x.SetUDField<System.Decimal>("Number09", reqRow.Number09);
        x.SetUDField<System.Decimal>("Number10", reqRow.Number10);
        x.SetUDField<System.Decimal>("Number20", reqRow.Number20);
        Db.Validate();
    }
  }
}

```

 ![image](https://www.epiusers.help/uploads/default/original/3X/5/b/5b385ae99968e0a870d27fb530ebb634580a9f47.png)

---

<div class="post-metadata">

**Author:** ![JeffSanders](https://www.epiusers.help/user_avatar/www.epiusers.help/jeffsanders/32/11196_2.png) [@JeffSanders](https://www.epiusers.help/u/JeffSanders)\
**Post date:** [June 14, 2023, 1:48pm UTC](https://www.epiusers.help/t/bpm-data-directive-custom-code/103896/13 "2023-06-14T13:48:48Z")

</div>

I found the PODetail.Number08 was defined as an integer. The BPM works now.
