How to auto-generate Part Number?

,

Dear Team,

I’m trying to generate part number is auto-generation based on Item Group and Item-Subgroup. I used the below code. I’m trying the below code in BPM Method directive - (Pre-Processing.)

BPM Code:

string ItemGrp = string.Empty;
string ItemSubGrp = string.Empty;
string tmpConcateItemGrp = string.Empty;
int AutoGenNum = 0;
int incvalue=0;

var ttPartRow = ( from g in ttPart where (g.RowMod == “A”) select g ).FirstOrDefault();
if (ttPartRow != null)
{
ItemGrp = Convert.ToString(ttPartRow[“Item_Group_c”]);
ItemSubGrp = Convert.ToString(ttPartRow[“Item_SubGroup_c”]);

tmpConcateItemGrp = Convert.ToString(ItemGrp) + Convert.ToString(ItemSubGrp);
var dbPartRow = Db.Part.AsEnumerable().Where(x => x.PartNum.StartsWith(tmpConcateItemGrp)).Select(p => p[“PartNum”]);
if(dbPartRow.Count()> 0)
{
incvalue = dbPartRow.AsEnumerable().Select(x => Convert.ToInt32(x.ToString())).Max(); // this line am getting the error message like Input String was Not correct Format. But i’m using same code in another enhancement working fine.
AutoGenNum=Convert.ToInt32(incvalue)+1;
ttPartRow.PartNum = Convert.ToString(AutoGenNum);
ttPartRow.InActive = true;
}

else
{
ttPartRow.PartNum = Convert.ToString(tmpConcateItemGrp.ToString()) + AutoGenNum.ToString(“0001”);
ttPartRow.InActive = true;
}
}

I don’t think you can do this in a BPM.

Which BO and Method are you using?

Have you checked out this thread?
https://www.epiusers.help/t/auto-numbering-customer-id/43884/10

2 Likes

i written the code in " Erp.Part.Update " and used in “Pre-Processing” method.

Dear Team,

Thanks for your help. I fixed the above issue. The below is working code

BPM Code:

string ItemGrp = string.Empty;
string ItemSubGrp = string.Empty;
string tmpConcateItemGrp = string.Empty;
int AutoGenNum = 0;
int incvalue=0;

var ttPartRow = ( from g in ttPart where (g.RowMod == “A”) select g ).FirstOrDefault();
if (ttPartRow != null)
{
ItemGrp = Convert.ToString(ttPartRow[“Item_Group_c”]);
ItemSubGrp = Convert.ToString(ttPartRow[“Item_SubGroup_c”]);

tmpConcateItemGrp = Convert.ToString(ItemGrp) + Convert.ToString(ItemSubGrp);
var dbPartRow = Db.Part.AsEnumerable().Where(x => x.PartNum.StartsWith(tmpConcateItemGrp)).Select(p => p[“PartNum”]);
if(dbPartRow.Count()> 0)
{
int tmp;
incvalue = dbPartRow.AsEnumerable().Select(x => int.TryParse(x.ToString(),out tmp) ? tmp : 0).Max(); // Modified Code
// incvalue = dbPartRow.AsEnumerable().Select(x => Convert.ToInt32(x.ToString())).Max(); // Before used Code
AutoGenNum=Convert.ToInt32(incvalue)+1;
ttPartRow.PartNum = Convert.ToString(AutoGenNum);
ttPartRow.InActive = true;
}

else
{
ttPartRow.PartNum = Convert.ToString(tmpConcateItemGrp.ToString()) + AutoGenNum.ToString(“0001”);
ttPartRow.InActive = true;
}
}