# LaborAdapter.SelectForWork exception
**Category:** [Epicor ERP 10](https://www.epiusers.help/c/e10/5)
**Created:** 2016-12-27 18:25 UTC
**Views:** 5619
**Replies:** 22
**URL:** https://www.epiusers.help/t/laboradapter-selectforwork-exception/36723
---
## Post #1 by @Chris_Conn
Can anyone help me get to the bottom of this exception from LaborAdapter.SelectForWork:
Labor Header has not changed.
Doing trace I can see that prior to that call there is:
LaborAdapter.GetNewLaborDtlOnSelectForWorkMethod
I figure I have to get a new labor dtl but it wants me to pass in laborHedSeq. Where do I get this? I do not see a call in the trace to GetNewLaborHed so how did the MES screen know what value to pass there?
I am sure that most of this issue is my lack of understanding the tables and their uses in the system as a whole.
---
## Post #2 by @josecgomez
When you Clock In a LaborHed record is created you can do a lookup on it for activetrans = true that gets you the LaborHed Seq...
---
## Post #3 by @Chris_Conn
And Jose to the rescue again. Off the top of your head, am I better off going through an adapter for that query or just using a BAQ with current emp and activetrans = true?
---
## Post #4 by @josecgomez
You can do LaborAdapter.GetRows and pass a whereClause or write a BAQ>.. that is upto you :-)
---
## Post #5 by @Chris_Conn
Jose wins.
```cs
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
bool more;
opts.PageSize = 20; //return this many
string whereSeq = string.Format("ActiveTrans = TRUE and EmployeeNum = '{0}'",((Ice.Core.Session)oTrans.Session).EmployeeID.ToString());
opts.NamedSearch.WhereClauses.Add("LaborHed",whereSeq);
var lbr = adapterLabor.GetRows(opts, out more);
MessageBox.Show(lbr.Tables[0].Rows[0]["LaborHedSeq"].ToString());
```
---
## Post #6 by @Chris_Conn
@josecgomez.trigemco
But wait there's more!
I am passing these params to GetNewLaborDtlOnSelectForWork:
And I get this wonderful exception:
That exception happens only once. If I try again it doesn't occur (although I am still getting "Labor Header has not changed")
---
## Post #7 by @josecgomez
What params... paste the code..
---
## Post #8 by @Chris_Conn
```cs
adapterLabor.GetNewLaborDtlOnSelectForWork(Convert.ToInt32(lbr.Tables[0].Rows[0]["LaborHedSeq"].ToString()),epiUltraGridJobs.Selected.Rows[0].Cells["JobHead_JobNum"].Text,Convert.ToInt32(epiUltraGridJobs.Selected.Rows[0].Cells["JobOpDtl_AssemblySeq"].Text),Convert.ToInt32(epiUltraGridJobs.Selected.Rows[0].Cells["JobOpDtl_OprSeq"].Text),epiUltraGridJobs.Selected.Rows[0].Cells["JobOpDtl_ResourceGrpID"].Text,"B",out prompt);
```
3645, "F000007486",0,10,"PRGP0500","B"
Interestingly, I noted the error title referenced the wrong resource group so I removed some other test code where I was selecting the group in the title. Now, the error title is:
Oooh, maybe I need to pass the resource group of the Employee :blush:
Nope - No change. :cry:
---
## Post #9 by @Chris_Conn
Table: LaborDtl
Company='CP' LaborHedSeq='3645' LaborDtlSeq='136612' SysRowID='00000000-0000-0000-0000-000000000000': ForeignKeyConstraint LaborHedLaborDtl requires the child key values (CP, 3645) to exist in the parent table. ---> System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
---
## Post #10 by @josecgomez
It thinks that the LaborHead doesn't exist...
Run a Trace on this manually and make sure you are making all the correct calls.
---
## Post #11 by @Chris_Conn
There are a lot of calls I don't recognize, mainly IMPLs, a few of which appear to be loading the customization. Apologies in advance for this long post but I did trim it as much as possible, leaving only the relevant info. This is start to finish (of the working, default operation):
Ice.Proxy.BO.GenXDataImpl
GetList
XXXDefListTableset
Ice.Proxy.BO.GenXDataImpl
GetList
XXXDefListTableset
Ice.Proxy.BO.GenXDataImpl
GetRows
GenXDataTableset
Ice.Proxy.BO.GenXDataImpl
GetRows
GenXDataTableset
Ice.Proxy.Lib.BOReaderImpl
GetRows
System.Data.DataSet
Ice.Proxy.Lib.BOReaderImpl
GetRows
System.Data.DataSet
Erp.Proxy.BO.EmpBasicImpl
GetList
EmpBasicListTableset
Erp.Proxy.BO.CompanyImpl
GetMaxWorkQueueRecords
System.Int32
Erp.Proxy.BO.WorkQueueImpl
GetOpsInResourceGroup
WorkQueueTableset
Erp.Proxy.BO.JobOperSearchImpl
GetRows
JobOperSearchTableset
Ice.Proxy.Lib.ClientCacheImpl
GetClassInformation
Ice.Tablesets.ClassAttributeTableset
Ice.Proxy.Lib.ClassAttributeImpl
GetAttributes
ClassAttributeTableset
0f81d587-c733-47da-87fa-2fdf18b46a7e
Erp.Proxy.BO.JCDeptImpl
GetList
JCDeptListTableset
Ice.Proxy.BO.NamedSearchImpl
GetRows
net.tcp://jpe10prod/E10LiveDB2/
NamedSearchTableset
Ice.Proxy.BO.QuickSearchImpl
GetBaseDefault
net.tcp://jpe10prod/E10LiveDB2/
System.Void
12/28/2016 08:39:06:1743869 AM
72
Erp.Proxy.BO.ResourceGroupImpl
GetList
ResourceGroupListTableset
Erp.Proxy.BO.CompanyImpl
GetMaxWorkQueueRecords
System.Int32
Erp.Proxy.BO.WorkQueueImpl
GetOpsInResourceGroup
WorkQueueTableset
>
Erp.Proxy.BO.OpMasterImpl
GetList
OpMasterListTableset
Erp.Proxy.BO.LaborImpl
GetRows
LaborTableset
Erp.Proxy.BO.LaborImpl
GetNewLaborDtlOnSelectForWork
System.Void
Ice.Proxy.BO.GenXDataImpl
GetList
XXXDefListTableset
1aef008a-117d-431a-a9e0-9ebf7a13bb9e
Ice.Proxy.BO.GenXDataImpl
GetList
XXXDefListTableset
1aef008a-117d-431a-a9e0-9ebf7a13bb9e
Ice.Proxy.Lib.BOReaderImpl
GetList
System.Data.DataSet
Erp.Proxy.BO.LaborImpl
SelectForWork
net.tcp://jpe10prod/E10LiveDB2/
System.Void
Erp.Proxy.BO.LaborImpl
CheckWarnings
net.tcp://jpe10prod/E10LiveDB2/
System.Void
Erp.Proxy.BO.LaborImpl
CheckFirstArticleWarning
net.tcp://jpe10prod/E10LiveDB2/
System.Void
Erp.Proxy.BO.LaborImpl
Update
net.tcp://jpe10prod/E10LiveDB2/
System.Void
12/28/2016 08:39:31:7015325 AM
226
Erp.Proxy.BO.CompanyImpl
GetMaxWorkQueueRecords
net.tcp://jpe10prod/E10LiveDB2/
System.Int32
Erp.Proxy.BO.WorkQueueImpl
GetOpsInResourceGroup
net.tcp://jpe10prod/E10LiveDB2/
WorkQueueTableset
Erp.Proxy.BO.CompanyImpl
GetMaxWorkQueueRecords
System.Int32
Erp.Proxy.BO.WorkQueueImpl
GetOpsInResourceGroup
net.tcp://jpe10prod/E10LiveDB2/
WorkQueueTableset
12/28/2016 08:39:32:8711872 AM
469
Erp.Proxy.BO.LaborImpl
GetRows
net.tcp://jpe10prod/E10LiveDB2/
LaborTableset
---
## Post #12 by @josecgomez
That method in your trace doesn't appear to take any parameters in? Furthermore notice that they set the RowMod on LaborHead to U. Are you doing this?
```xml
Erp.Proxy.BO.LaborImpl
GetNewLaborDtlOnSelectForWork
System.Void
```
---
## Post #13 by @Chris_Conn
I assumed that was showing me that that call had made those changes. Am I wrong?
Here is the unabridged version of that call:
> Erp.Proxy.BO.LaborImpl
> GetNewLaborDtlOnSelectForWork
> net.tcp://jpe10prod/E10LiveDB2/
> System.Void
> 12/28/2016 08:39:21:4348315 AM
> 93
>
>
>
>
> CP
> cconn
> 3645
> 2016-10-19T00:00:00-05:00
> 1
> 2016-10-19T00:00:00-05:00
> 0.28
> 00:17
> 0.28
> 2016-10-19T00:00:00-05:00
> N
> 0.00
> 0.00
> 0.00
> 0.00
> 0
> 24:00
> 0
> 0.00
> false
> false
> true
>
> true
>
>
>
>
>
> false
> false
> 0.00000
> 0.00000
> 0.00000
> 585442701
> 280f8dff-1cb2-4ff1-98b6-5267b66e259e
> false
> false
> 0.00
> 1
>
> false
> empphoto/CP/.bmp
> false
> false
> false
> false
> 40.29
> 49.21
> false
> 0
> Chris
> Chris P Conn
> Conn
> 7:00 AM to 3:00 PM
> U
>
>
>
>
>
>
>
>
>
>
>
>
>
> 00000000-0000-0000-0000-000000000000
>
>
>
>
>
>
>
>
>
---
## Post #14 by @josecgomez
Right but if you see the paramDataSetChanges that means changes to the dataset that occurred before calling the method, so set LaborHed.RowMod="U"
---
## Post #15 by @Chris_Conn
Make those changes in the Labor dataset or in the DB?
---
## Post #16 by @josecgomez
In the LaborDataset set the LaborHed.RowMod="U" (RowMod doesn't exist in the data set)
---
## Post #17 by @Chris_Conn
I am going with:
var lbr = adapterLabor.GetRows(opts, out more);
lbr.Tables[0].Rows[0]["RowMod"] = "U";
No apparent change. Let me check the trace.
---
## Post #18 by @josecgomez
Sure! However you can use the typed dataset to make your life easier, using quoted strings is error prone
```cs
LaborDataSet lds = adapterLabor.GetRows(opts, out more);
lds.LaborHed[0].RowMod="U";
```
Also I think your adapterLabor is named wrong... is that an adapter? Adapters (generally) don't return values. How are you instantiating that? (Edit never mind, but you can still cast it to LaborDataSet)
---
## Post #19 by @Chris_Conn
```cs
private LaborAdapter adapterLabor;
adapterLabor = new LaborAdapter(this.oTrans);
adapterLabor.BOConnect();
...
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
bool more;
opts.PageSize = 20; //return this many
string whereSeq = string.Format("ActiveTrans = TRUE and EmployeeNum = '{0}' and COMPANY = '{1}'",((Ice.Core.Session)oTrans.Session).EmployeeID.ToString(),((Ice.Core.Session)oTrans.Session).CompanyID.ToString());
opts.NamedSearch.WhereClauses.Add("LaborHed",whereSeq);
adapterLabor.LaborData.Clear();
var lbr = adapterLabor.GetRows(opts, out more);
```
---
## Post #20 by @josecgomez
Yeah never mind I saw it after I posted, you can cast that var lbr into a LaborDataSet to make your life easier (I think)
Can you post your entire code I think I know what your issue is.
---
## Post #21 by @Chris_Conn
What ref do I use for it?
The type or namespace name 'LaborDataSet' could not be found (are you missing a using directive or an assembly reference?)
---
## Post #22 by @josecgomez
using Erp.BO
You'll need to bring in Erp.Contracts.BO.Labor.dll
---
## Post #23 by @Chris_Conn
Ok so it was a 2 part puzzle, and Jose solved both pieces:
First, the exception was caused because I did not have any data in the LaborAdapters.LaborData (I had loaded it into a dataset). To solve, I used the LaborAdapter.GetById(LaborHedSeq)
Also, once data was populated in LaborAdapter.LaborData I had to set it as modified:
LaborAdapter.LaborData.LaborHed[0].RowMod="U";
You have to do this before calling: Labor.GetNewLaborDtlOnSelectForWork()
//And finally these - Especially UPDATE!
adapterLabor.SelectForWork();
adapterLabor.CheckWarnings(out pcMsg);
adapterLabor.CheckFirstArticleWarning(out pcMsg);
adapterLabor.Update();
Thanks Jose - You ready to give up that paypal email yet so I can start buying you beers?
---
**Canonical:** https://www.epiusers.help/t/laboradapter-selectforwork-exception/36723
**Original content:** https://www.epiusers.help/t/laboradapter-selectforwork-exception/36723