lundi 23 février 2015

OnDelete Event Receiver delete associated item



I have 2 lists. List A creates a record in List B on the creation of a record in List A. So, I'd like to complete the circle by deleting the the item in List B when the record is deleted in List A.


The relation is as follows:



List A
---------
EmpName (Person Field)
txtEmpName (Single line of text)


List B
---------
Emp (Lookup on txtEmpName)


In an OOB workflow or via list web service I can usually get the list item ID from the value of the look up field value. I am trying to do this from an Event Receiver but I get the raw text value. See below:



using (web)
{
SPList list = web.Lists["List B"];

foreach (SPListItem item in list.Items)
{
//item["emp"] = "1;#Joe Smith"
if ((int)item["emp"] == properties.ListItemId)
{
item["OnDeletingOutcome"] = "This Item should be deleted";
item.Update();
}
}
}







0 commentaires:

Enregistrer un commentaire