Data Directive Help

I have an In-Transaction data directive on Part.Update.
What I am trying to do is set the part and site inspection required dropdown to inspection required IF:

  • Part.typecode is P
  • part.ClassID is in “RHVA”, “RINS”, “RMET”, “ROTH”
  • PartPlant.Plant equals LOU

It’s failing where I have the var partPlant section. there is no error message it just doesn’t see that part to pick up the partPlant.Plant.

If I comment out that section and the partPlant.Plant ==“LOU” in the if statement it works.

bool isNewPart = false;

var partRow = ttPart.FirstOrDefault();

if (partRow != null && partRow.RowMod == "A")
{
   isNewPart = true;
}

bool requiresInspection = partRow != null &&
   partRow.TypeCode == "P" &&
   new[] { "RHVA", "RINS", "RMET", "ROTH" }.Contains(partRow.ClassID);

var partPlant = (from s in Db.PartPlant
                where s.Company == partRow.Company && s.PartNum == partRow.PartNum
                select s).FirstOrDefault();
                
 if (isNewPart && requiresInspection && partPlant !=null && partPlant.Plant == "LOU")
 {
     partRow.RcvInspectionReqPart = "Y";
     partPlant.RcvInspectionReqPart = "Y";
 } 

If it’s a new part, then you probably don’t have a part plant record created yet to look one up in the database on part creation. Also, you can’t really update a partPlant record in a data directive for Part without calling Db.SaveChanges() because the part plant table isn’t in the dataset for that call to change.

But honestly, I would move this to a method directive anyways, because a data directive is a lot more siloed to a single table and you are trying to update 2 tables at a time. If you do this is a method directive, you should have the part dataset and a part plant dataset to manipulate.

2 Likes

Thanks! I’ll give that a try.