Need help with "Failed to enable constraints" error

We have a customization for Job Entry that requires adding an EpiButton that fires off the “Add Operation” function as if it were right-clicked from the tree menu.

I used the “Business Logic Method Call” customization wizard with the JobEntryAdapter and the GetNewJobOper method, passing the job number from the DataView (after the job has been created) and assembly seq value of 0 into the method, called by the button click event:

private void btnAddNewOp_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		CallJobEntryAdapterGetNewJobOperMethod();
	}

	private void CallJobEntryAdapterGetNewJobOperMethod()
	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			EpiDataView edvJobHead = ((EpiDataView)(this.oTrans.EpiDataViews["JobHead"]));

			// Check if valid EpiDataView Row(s) are selected
			if ((edvJobHead.Row < 0))
			{
				return;
			}

			// Declare and create an instance of the Adapter.
			JobEntryAdapter adapterJobEntry = new JobEntryAdapter(this.oTrans);
			adapterJobEntry.BOConnect();

			// Declare and Initialize Variables
			// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
			string jobNum = ((string)(edvJobHead.dataView[edvJobHead.Row]["JobNum"]));
			int assemblySeq = 0;
			
			// Call Adapter method
			bool result = adapterJobEntry.GetNewJobOper(jobNum, assemblySeq);

			// Cleanup Adapter Reference
			adapterJobEntry.Dispose();
			
		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}

But when I create a new job, add a part and product group, save, then hit the button, I get this error message:

The summary is : "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Table: JobOper
Company=‘DCS’ JobNum=‘500925’ AssemblySeq=‘0’ OprSeq=‘10’ SysRowID=‘00000000-0000-0000-0000-000000000000’: ForeignKeyConstraint AsmblOper requires the child key values (DCS, 500925, 0) to exist in the parent table."

What is this referring to? I’ve tried BPMs (pre and post) on the GetNewJobOper method to set those fields on the JobHead, JobOper, and JobAsmbl tables to no avail. What else should I do?

Did you confirm that this is preventing your button from working? IIRC, this is the same error that appears if you create a configurator, save it, and immediately delete it. (Or delete it at any point.) But delete still works.

@KevinK I’m not sure what you mean, except to say that the button fails to create a new operation, and that error flashes, so…

Interestingly enough (or not), when I try to do something similar, but with adding new job material instead, invoking the GetNewJobMtl method, I get a similar error:

This time it’s referring to the “AsmblMtl” constraint.

@Matthew_Morgan I just mean that sometimes that error appears but it doesn’t seem to interfere with whatever you were trying to do. Sounds like in your case it does.

I didn’t make it clear: when using the custom button, the error message appears, and the New Operation is not added.

The job assembly 0 do not seem to exist. You cannot create a JobOper or a JobMtl if the JobAsmbl does not exist. Can you look in the database to see if the JobAsmbl exist for the job you are using?

If it didn’t exist, how would I add it or create it? And would that not be handled already by the GetNewJobOper method?

I revise your code, and you are declaring a new adapter, so the job and the assembly are not in the dataset of the adapter.
So you should do a GetByID to retrieve the job info before adding your operation.

Like that:
adapterJobEntry.GetByID(jobNum);
adapterJobEntry.GetNewJobOper(jobNum, assemblySeq);

But declaring a new adapter and having to retrieve the data already there is not the best ways.

You should simply call the existing method in the transaction, like this:

private void btnAddNewOp_Click(object sender, System.EventArgs args)
{
oTrans.GetNewJobOper();
}

1 Like

Many thanks, @Louque77 …this simple adjustment helped me clear a major hurdle!

1 Like