Printing "Parentage" on subassemly travelers

I don’t know how else to read from a table until a condition is met, but happy to learn :slight_smile:

edit: I could add a safety valve… like if my string length gets to the max it can hold then just stop and write “undefined” instead or something.

Let me look at it. What you wrote there is an infinite loop :rofl:

I’m trusting that it’s not possible to have a Job that does NOT terminate at 0 (top level) or have a circular reference in the tree.

currentparent does not change in your loop

Well it’s supposed to … just poor commenting. The idea is I walk through parent/asm relationship until I find the track to 0 and then exit the loop, write value, do the next Asm record.

Does the MOM change after Get Details? If not, you might want to think about putting something on the Get Details method. :man_shrugging:t2:

I did this with a MD and C#. I prefer “Lineage” over “Parentage”.
DaveO

Me too, now that you mentioned it. :laughing:

Nice - I considered Lineage and Ancestry … maybe PathToThrone?

Love some help with my syntax, or referral to juicy documentation that’s missing from my life.

1 Like

This choice is certainly open for critique as well. I thought I chose a switch where the method is effectively frozen - would have to un-release to make a change to the Asm hierarchy.

I found some samples on github … no syntax errors. Shall I give it a whirl?

// csharp
string parentage = "";
int currentAsm = 0;
int currentParent = 0;
Erp.Tablesets.JobAsmblRow jobAsm_row;

foreach(var currentRow in ds.JobAsmbl)
{
  parentage = currentRow.Parent.ToString(); // initialize string
  currentAsm = currentRow.AssemblySeq; // grab Assembly number of each row
  currentParent = currentRow.Parent; // grab Parent seed of each row
  
  do
  {
    parentage = parentage + "~"; // add delineator
    currentAsm = currentParent; //swap in Parent for Asm to search for next BOM level
    jobAsm_row = (from JobAsmRow in ds.JobAsmbl where JobAsmRow.AssemblySeq == currentAsm select JobAsmRow).FirstOrDefault();
    currentParent = jobAsm_row.Parent; // set next Parent value
    parentage = parentage + currentParent.ToString(); // add next non-zero parent to string
  }while(currentParent != 0);
  
  // write Parentage to custom field in each row
  currentRow.SetUDField<string>("Parentage_c", parentage);
}

First thought is that I don’t really know the scope of ds.JobAsmbl in this context. Already filtered for the JobNum I’m releasing?

Where is the UD field you are going to store this in?

JobAsmbl

Added safety valve JIC. Also moved to JobEntry.Update pre-proc because my other idea did not even trigger. But I’m getting zero iterations because ds.JobAsmbl.Count = 0
:confused: