BPM call custom code Service

Hi,

Can any one get me on the road. I need function which finds all partnums in specific period of time and adds whse codes to them. But the question how to use service to add whse code to part.
I have added Part ref to assemblies and have this code, but it is incorect, it does not contain anything about whse, only part info. Can any one tell me how this should look like in correct way:

var part = ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(Db);
Erp.Tablesets.PartTableset partTs = new Erp.Tablesets.PartTableset();
part.GetNewPartWhse(ref partTs,  "MyPart", "MyPlant");
partTs.Part[0].WarehouseCode = "BEND";
part.Update(ref partTs);

Do a Trace and then replicate the trace in code. You’ll have to do a Part.GetByID first, then call the GetNewPartWhse, fill that out etc.

A trace is your best friend.

2 Likes

Hi,

Did it in this way, it seams that it work until there is no iteration id db table, but when i iterate I get this error:


Don’t know how to solve this. My code look like this:

var timeback = DateTime.UtcNow.AddDays(-1);

List <string> whslist = new List<string>();
whslist.Add("ASMBL");
whslist.Add("BEND");
whslist.Add("CNC");
whslist.Add("CNCW");
whslist.Add("MECH");
whslist.Add("PC D");
whslist.Add("SPOT");
whslist.Add("WELD");



foreach(var partrow in(from rows in Db.Part where rows.Company.ToUpper() == "XXX" && rows.CreatedOn > timeback select rows.PartNum))
{


foreach(var whcode in whslist)
{

var part = ServiceRenderer.GetService<Erp.Contracts.AddPartWhseSvcContract>(Db);
part.CreatePartWhse( partrow, "MfgSys",whcode);
}
}

LINQ won’t work here because you need the whole part dataset to work with. Start the trace, go to Part Entry and add a whse to a part. Stop the trace, go to your trace log and see what methods are called there. Assuming you already covered the cases where those warehouses are already added and you don’t try to add them again, you’ll need at least the following:
Part.GetByID
Part.GetNewPartWhse
Part.Update

Don,t know why but this works, but if you say that it needs to rebuild full dataset I am afraid that this could do some bad stuff. Althought BO ref describes this method like this:

var timeback = DateTime.UtcNow.AddDays(-1);

var partlist = (from rows in Db.Part where rows.Company.ToUpper() == "XXX" && rows.CreatedOn > timeback select rows.PartNum).ToList();
foreach(var ttpart in partlist)
{

var part = ServiceRenderer.GetService<Erp.Contracts.AddPartWhseSvcContract>(Db);
part.CreatePartWhse( ttpart, "MfgSys","ASMBL");
part.CreatePartWhse( ttpart, "MfgSys","BEND");
part.CreatePartWhse( ttpart, "MfgSys","CNC");
part.CreatePartWhse( ttpart, "MfgSys","CNCW");
part.CreatePartWhse( ttpart, "MfgSys","MECH");
part.CreatePartWhse( ttpart, "MfgSys","PC D");
part.CreatePartWhse( ttpart, "MfgSys","SPOT");
part.CreatePartWhse( ttpart, "MfgSys","WELD");

So since everyone saying to rebuild full ds, seems this is too tricky even by using epicor documentation, if I do this like this, whole application stops after code trigers:

var part = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(Db);
var PartTS = new PartTableset();
PartTS = part.GetByID("judtest1");
part.GetNewPartWhse(ref PartTS, "judtest1", "MfgSys");
PartTS.PartWhse[0].WarehouseCode = "PC D";
part.Update(ref PartTS);

You’re almost there. Again, you may already have warehouses added there, so changing the first record is not correct. Try this:

PartTS.PartWhse[PartTS.PartWhse.Count - 1].WarehouseCode = "PC D";

no luck. I got tired, I dont understand what am I missing. It still freezes the app with no error, from the first glance it looks like it is calculating bunch of data, because mouse wheel keeps spinning, so I need to do task kill, and reopen the app after few mins. I have read almost all topics related with getbyid and getnew, for me seams that this should work but for sure I miss something if this happening.

Here’s the function I used to test this. It works for me on my version. Make sure you change the owner and then add your companies in the Security tab before you test it.

TEST.efxb (15.5 KB)

Your’s script wokrs fine. I will compare what I did wrong in my logic. THANKS

Hi,

One more question, maybe you would have an idea. If the same function submited on pilot it runs smoothly if it is submited on Live for the same part with the same conditions it runs and creates warehouses as it should but monitor displays notification:


Could it be some bo bug on environment? Because Pilot and Live Db data are equal, and script are the same

I may be way off since you’re on a totally different version but maybe you’re trying to overwrite the warehouse that’s set as primary ? Like the record is already there. Are you doing any checks to see if the warehouse is already added ?

Did some test, one difference between environments, on Live same part has a reference to the job, if I pick part which has no ref to job, then there are no such warnings. But probably until script creates warehouses and just displays warning, I can be calm, maybe :slight_smile: