I am trying to use a function to change a part to be serial tracked. But for some reason the function does nothing. No error that I can see and the part is not set as Serial Tracked. Usually when that happens I have forgotten to set the RowMod = “U” but not in this case.
Here is the code from the function. I have added a reference to the ERP.BO.Part service.
// Create PartService BO.
this.CallService<Erp.Contracts.PartSvcContract>(BO =>
{
var ds = BO.GetByID(partNum);
// Set part as serial tracked.
ds.Part.FirstOrDefault().TrackSerialNum = true;
ds.Part.FirstOrDefault().RowMod = "U";
BO.ChangePartTrackSerialNum(true, ref ds);
BO.Update(ref ds);
});
I have pretty much the same code in a BPM and that is working. The BPM updates other part details as well.
I also did a trace in the client to see what method calls it uses and there was the ChangePartTrackSerialNum call twice. Interestingly that didnt have the rowmod=U.
The function did have more code that would first create the part and then set it as serial tracked. That would create the part and set all the other details. I removed all the code to create the part to concentrate on the serial track issue.
Yep serial tracking is on at the Site. I can also check the track serial check box in the part entry screen so I assume the setup of every thing is good.
Looks good to me. The only other thing I can add is did you do a full trace of turning the flag on and then use that to create the function? If not, you might be missing a method call that needs to happen.
looking at the trace it’s ChangePartTrackSerialNum
If you were going to just attempting to update the flag and forget about any special processing that is done by the BO then you would add the table as a reference, set it to updatable and then use the Db.SaveChanges();
in the middle of doing a system recovery… so responses are slow
I did another trace to double check and updated the function to call the same methods… Still not changing the trackSerial checkbox. And I don’t get any output messages.
updated code.
// Create PartService BO.
this.CallService<Erp.Contracts.PartSvcContract>(BO =>
{
var ds = BO.GetByID(partNum);
// Set part as serial tracked.
ds.Part.FirstOrDefault().TrackSerialNum = true;
ds.Part.FirstOrDefault().EnableSerialNum = true;
ds.Part.FirstOrDefault().RowMod = "U";
BO.ChangePartTrackSerialNum(true, ref ds);
BO.ChangePartTrackSerialNum(true, ref ds);
string cPartChangedMsgText, cPartSNChangedMsgText;
BO.CheckPartChanges(ds, out cPartChangedMsgText, out cPartSNChangedMsgText);
BO.Update(ref ds);
output = $"{cPartChangedMsgText} {cPartSNChangedMsgText}";
});
The code you posted the first time works perfectly for me. But I had to go in and set a serial mask/format for the part first. I did that in Part entry. I think that’s the piece you’re missing.