# Programtically End Activity

**URL:** <https://www.epiusers.help/t/programtically-end-activity/57568>\
**Category:** Epicor ERP 10\
**Tags:** custom-code\
**Created:** [July 8, 2019, 5:25pm UTC](https://www.epiusers.help/t/programtically-end-activity/57568 "2019-07-08T17:25:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattSpotts](https://www.epiusers.help/user_avatar/www.epiusers.help/mattspotts/32/101155_2.png) [@MattSpotts](https://www.epiusers.help/u/MattSpotts)\
**Post date:** [July 8, 2019, 5:25pm UTC](https://www.epiusers.help/t/programtically-end-activity/57568/1 "2019-07-08T17:25:08Z")

</div>

I am trying to auto end all activities in the production tab of MES. I remember doing this before but having this same issue and can’t remember how to resolve it. here is my code. I get the error that the labordtl record has not changed then when it hits the change before the update I get can’t change an active transaction. Any help would be greatly appreciated.

foreach(Infragistics.Win.UltraWinGrid.UltraGridRow UGR in ProdGV.Rows)  
{

```
		ProdGV.ActiveRow = UGR;
		
		LaborAdapter Ladap = new LaborAdapter(this.MESMenu);
		Ladap.BOConnect();
		int iLaborHedSeq;
		int.TryParse(UGR.Cells[2].Text,out iLaborHedSeq);
		int iLaborDtlSeq;
		int.TryParse(UGR.Cells[3].Text,out iLaborDtlSeq);
		//int iLaborDtlSeq = UGR.Cells[3].Value;
		Boolean GDTL = Ladap.GetDetail(iLaborHedSeq, iLaborDtlSeq);
			
		Boolean EAWorked = Ladap.EndActivity();
		
		string msg;			
		Boolean setqty = Ladap.DefaultLaborQty(1,out msg);
		Ladap.LaborData.LaborDtl[0]["LaborQty"] = 1;
		Ladap.Update();
		
		Ladap.Dispose();
	}
```

---

<div class="post-metadata">

**Author:** ![tsmith](https://www.epiusers.help/user_avatar/www.epiusers.help/tsmith/32/64774_2.png) [@tsmith](https://www.epiusers.help/u/tsmith)\
**Post date:** [July 8, 2019, 5:34pm UTC](https://www.epiusers.help/t/programtically-end-activity/57568/2 "2019-07-08T17:34:24Z")

</div>

I have a BPM that ends labor activity. I had to process the records in the following order:

1. Get the record (Labor.GetDetail)
2. Set LaborDtlRow.RowMod = “U”
3. Call Labor.EndActivity method
4. Call Labor.Update method  
 ![image](https://epiusers.help/uploads/default/original/3X/2/f/2f908679e28ba25fb68063e51bc5f137ea091ec2.png)  
 ![image](https://epiusers.help/uploads/default/original/3X/3/6/361f6b9620ddd1f7c0cc1a7bbf898aa893813bb0.png)  
Looks like you just need to add step 2 after you get the detail record.

---

<div class="post-metadata">

**Author:** ![MattSpotts](https://www.epiusers.help/user_avatar/www.epiusers.help/mattspotts/32/101155_2.png) [@MattSpotts](https://www.epiusers.help/u/MattSpotts)\
**Post date:** [July 8, 2019, 5:44pm UTC](https://www.epiusers.help/t/programtically-end-activity/57568/3 "2019-07-08T17:44:22Z")

</div>

Wow. As soon as I read your steps It dawned on me. This is definitely not the first time this has happened to me. Thank you so much.

---

<div class="post-metadata">

**Author:** ![A.Baeisa](https://www.epiusers.help/user_avatar/www.epiusers.help/a.baeisa/32/8988_2.png) [@A.Baeisa](https://www.epiusers.help/u/A.Baeisa)\
**Post date:** [July 9, 2019, 12:50pm UTC](https://www.epiusers.help/t/programtically-end-activity/57568/4 "2019-07-09T12:50:59Z")

</div>

calling End Labor Activity BO method should has LaborDtl.Update included in it.
