# BPM Custom Code to sort open Op list by OprSeq

**URL:** <https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539>\
**Category:** Epicor ERP 10\
**Tags:** bpm\
**Created:** [May 9, 2024, 7:51pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539 "2024-05-09T19:51:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 9, 2024, 7:51pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/1 "2024-05-09T19:51:52Z")

</div>

Hi All, I can’t seem to figure out how to get this to work assuming I even can. I have a UD\_Field that gets updated by BPM with custom code to list open operations by OpCode. There is no sort and when looking at it it’s just random. I want the list to display the operation code but in the proper open operation sequence. 10, 20, 30 40 and so on. But to dispaly as Laser, Weld, Machine, OutSide Sub.

This is what I have…

```cs
foreach (var iJobOper in 
    (from rJobOper in ttJobOper
      select rJobOper)
  ) {
  var xJobOper = iJobOper;

  foreach (var iJobAsmbl in 
      (from rJobAsmbl in Db.JobAsmbl
        where string.Compare(rJobAsmbl.Company, xJobOper.Company, true) == 0 
          && string.Compare(rJobAsmbl.JobNum, xJobOper.JobNum, true) == 0 
          && rJobAsmbl.AssemblySeq == xJobOper.AssemblySeq 
        select rJobAsmbl)      
    ) {
    var dbJobAsmbl = iJobAsmbl;

    var xOpCode_List = "";

    foreach (var idbJobOper in
            (from rdbJobOper in Db.JobOper
             where string.Compare(rdbJobOper.Company, dbJobAsmbl.Company, true) == 0
                 && string.Compare(rdbJobOper.JobNum, dbJobAsmbl.JobNum, true) == 0
                 && rdbJobOper.AssemblySeq == dbJobAsmbl.AssemblySeq
                 && rdbJobOper.JobComplete == false
                 && rdbJobOper.OpComplete == false
             orderby xJobOper.AssemblySeq, rdbJobOper.OprSeq   
             select rdbJobOper)
        ) {
      var dbJobOper = idbJobOper;

      if (xOpCode_List == "")
        xOpCode_List = dbJobOper.OpCode;
      else
        xOpCode_List = xOpCode_List + ", " + dbJobOper.OpCode;

    }

    dbJobAsmbl.OpenOp_c = xOpCode_List;

  }

}

```

EDIT: I wrapped your code in grave accents to highlight it correctly, so I can read it… Details are in the reply dialog before you type.

---

<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:** [May 9, 2024, 8:40pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/2 "2024-05-09T20:40:57Z")

</div>

To get the output in that order use orderby fieldname ascending is assumed You can google C# linq orderby.

Depending on where and how often this is called then with(nolock) and possibly joining into one call to the Db to make one list would be best.

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 12:27pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/3 "2024-05-10T12:27:55Z")

</div>

I can’t seem to figure out where to get the orderby placed. I’ve tried a few places and it doesn’t take it. Not sure what C# linq is. I’m not a programmer, self-taught.

---

<div class="post-metadata">

**Author:** ![kve](https://www.epiusers.help/user_avatar/www.epiusers.help/kve/32/76150_2.png) [@kve](https://www.epiusers.help/u/kve)\
**Post date:** [May 10, 2024, 1:16pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/4 "2024-05-10T13:16:16Z")

</div>

You want it ordered by OprSeq, but listing only the OpCode? It looks like you’re already sorting by OprSeq in your rdbJobOper query. It’s not coming through in that order?

---

<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:** [May 10, 2024, 2:33pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/5 "2024-05-10T14:33:29Z")

</div>

ok, C# linq is what custom code is primarily in Epicor now. Where are you trying to get this sort done? Maybe you don’t need some of that code at all.

If you want to upload the bpm and what the output is supposed to be we can figure it out.

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 3:28pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/6 "2024-05-10T15:28:31Z")

</div>

It is not, they are random.

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 3:28pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/7 "2024-05-10T15:28:56Z")

</div>

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

 ![image](https://www.epiusers.help/uploads/default/original/3X/2/4/243a92fa7d0be90acb3d0f72cd2f35eb74252c08.png)

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 3:29pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/8 "2024-05-10T15:29:57Z")

</div>

Ok, I’ll need to take some C# linq classes. I keep getting asked for more custom tasks that require custom code. Thank you!

---

<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:** [May 10, 2024, 3:34pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/9 "2024-05-10T15:34:34Z")

</div>

So this is on OpComplete, but not in MES? What is this supposed to do?

---

<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:** [May 10, 2024, 4:11pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/10 "2024-05-10T16:11:23Z")

</div>

> [@jenjen7981](#):
>
> C# linq classes.

I started a “Code Camp” thread, that may help. We haven’t tackled LINQ specifically, but it’s on the _ **todo** _ list.

There is quite a bit of LINQ in there already I believe, at least in the comments.

> [@Kinetic Code Camp - Bring your skills, or lack thereof.. dumpster\_fire](https://www.epiusers.help/t/kinetic-code-camp-bring-your-skills-or-lack-thereof/113349):
>
> Welcome to Code Camp! fire dumpster_fire fire Please bear with me while I reserve a few posts and get some content in here. Continuing from here: [Any Interest in a Coding Camp Type Thread?](https://www.epiusers.help/t/any-interest-in-a-coding-camp-type-thread/113271) There seems to be enough interest in this, so I am going to get it started. In this thread we will both lay out some pre-defined topics, as well as answer questions. I encourage you to still ask questions in the main forums if your question is very specific and needs more help. This thread will prob…

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 4:24pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/11 "2024-05-10T16:24:50Z")

</div>

When an operation get’s completed or any change made to JobOper table, it writes the list of open operations to OpenOp\_C field. This field is then used on dashboards for production to reivew jobs and they can see what operations by OpCode are still open. It shows the open Ops, just not putting them in any order when you view on dashboard they are random. Listing op 10, 20 and so on doesn’t help determine if it’s getting machined next or need to go for outside sub for example.

---

<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:** [May 10, 2024, 4:56pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/12 "2024-05-10T16:56:28Z")

</div>

I have a routine that does this same process, but on the fly in a dashboard.

Export and upload your bpm and we can take a look. Your version just says 10. The earliest I have to work in is 10.2.400.

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 5:29pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/13 "2024-05-10T17:29:24Z")

</div>

We are on 10.2.200, but I’ll have .700 available very soon. Are routines new in Kinetic?

---

<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:** [May 10, 2024, 5:43pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/14 "2024-05-10T17:43:15Z")

</div>

They have existed since 10.2, but the last ones are in 11.1, so the tt to ds changed somewhere along the line.

If you want us to look upload the bpm.

---

<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:** [May 10, 2024, 6:43pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/15 "2024-05-10T18:43:20Z")

</div>

Greg can’t move very well, give the man something to do!

![Work From Home Sport GIF by UFC](https://media4.giphy.com/media/1w9V9NpuRkya7YXab6/giphy.webp?cid=e90edba3k3iy4r422agrqsrljnh2je06w7vkgt89wikcz4lu&ep=v1_gifs_search&rid=giphy.webp&ct=g)

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 10, 2024, 7:01pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/16 "2024-05-10T19:01:18Z")

</div>

Yes, I do. Thank you was pulled in 9 directions, yeehaaa!

[OpenOpList.bpm](https://www.epiusers.help/uploads/short-url/zAxOEcENVmtbEmUE1mln5lWJxwz.bpm) (33.2 KB)

---

<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:** [May 11, 2024, 5:18pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/17 "2024-05-11T17:18:57Z")

</div>

For my jobs it seems to get the correct ordering, but they are fairly simple. I took your routine and made as few changes as possible (rowmod was changed, so it did not run twice) and one I made closer to how I would write it and both produced the same list.

Can you add the write lines or use the below to see if your data somehow does not get ordered.

Since this is on a DD and is going to get hit a lot, I would bring all of the JobOpers records and only the fields needed from the Db once and then iterate that to make the list.

I added the comment at the top because I can’t stand seeing code in the action pane.  
The start and end show when the routine begins and ends. The list shows me in the severlog what is happening in the code.

![image](https://www.epiusers.help/uploads/default/original/3X/7/7/7730c2ec86044409c2d78dad6948d93edfd5d91a.jpeg)

```cs
/* calc open ops */

Ice.Diagnostics.Log.WriteEntry("Start Orig Calc");

foreach (var iJobOper in
(from rJobOper in ttJobOper where !rJobOper.Unchanged()
select rJobOper)
) {
  var xJobOper = iJobOper;

  foreach (var iJobAsmbl in
  (from rJobAsmbl in Db.JobAsmbl
  where string.Compare(rJobAsmbl.Company, xJobOper.Company, true) == 0
  && string.Compare(rJobAsmbl.JobNum, xJobOper.JobNum, true) == 0
  && rJobAsmbl.AssemblySeq == xJobOper.AssemblySeq
  select rJobAsmbl)
  ) {
    var dbJobAsmbl = iJobAsmbl;

    var xOpCode_List = "";

    foreach (var idbJobOper in
    (from rdbJobOper in Db.JobOper
    where string.Compare(rdbJobOper.Company, dbJobAsmbl.Company, true) == 0
    && string.Compare(rdbJobOper.JobNum, dbJobAsmbl.JobNum, true) == 0
    && rdbJobOper.AssemblySeq == dbJobAsmbl.AssemblySeq
    && rdbJobOper.JobComplete == false
    && rdbJobOper.OpComplete == false
    orderby xJobOper.AssemblySeq, rdbJobOper.OprSeq
    select rdbJobOper)
    ) {
      var dbJobOper = idbJobOper;

      if (xOpCode_List == "")
      xOpCode_List = dbJobOper.OpCode;
      else
      xOpCode_List = xOpCode_List + ", " + dbJobOper.OpCode;
      
      Ice.Diagnostics.Log.WriteEntry($"OList {idbJobOper.OprSeq}-{idbJobOper.OpCode} {idbJobOper.QtyCompleted:0}");

    }

    dbJobAsmbl.Character02 = xOpCode_List;
    Ice.Diagnostics.Log.WriteEntry($"OList {xOpCode_List}");

  }

}

Ice.Diagnostics.Log.WriteEntry("Exit Orig Calc");

```

---

<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:** [May 11, 2024, 5:50pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/18 "2024-05-11T17:50:54Z")

</div>

> [@gpayne](#):
>
> I can’t stand seeing code in the action pane

A little ocd isn’t a bad thing.

When you start flipping the light switch 27 times before you leave a room you may have a problem.

---

<div class="post-metadata">

**Author:** ![jenjen7981](https://www.epiusers.help/user_avatar/www.epiusers.help/jenjen7981/32/82044_2.png) [@jenjen7981](https://www.epiusers.help/u/jenjen7981)\
**Post date:** [May 11, 2024, 10:17pm UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/19 "2024-05-11T22:17:26Z")

</div>

I changed it to a method and modified when it updates. Still doesn’t sort correclty.  
 ![image](https://www.epiusers.help/uploads/default/original/3X/3/a/3ab2a81b842be85580ecbb93d906e674405927e9.png)

---

<div class="post-metadata">

**Author:** ![Mark\_Wonsil](https://www.epiusers.help/user_avatar/www.epiusers.help/mark_wonsil/32/51594_2.png) [@Mark\_Wonsil](https://www.epiusers.help/u/Mark_Wonsil)\
**Post date:** [May 12, 2024, 1:18am UTC](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539/20 "2024-05-12T01:18:51Z")

</div>

I know you’ve spent a couple of days on this but another option is to do the query in a BAQ and use string\_aggregate to generate your string.

> [@Sorting Contents of a StringAgg Subquery](https://www.epiusers.help/t/sorting-contents-of-a-stringagg-subquery/90826/14):
>
> Fixed: String\_Agg(RouteList.Calculated\_Comb,', ') Within group (order by RouteList.JobOper8\_OprSeq asc)

[Next page](https://www.epiusers.help/t/bpm-custom-code-to-sort-open-op-list-by-oprseq/114539.md?page=2)
