Error Creating PODetail from C#

I have c# code that fires when a button is clicked. I can create the PO header just fine, but get an error when trying to add the POLine. Here is my code:

	POAdapter adapterPO = new POAdapter(this.oTrans);
	adapterPO.BOConnect();

	adapterPO.GetByID(po);
	adapterPO.GetNewPODetail(po);

	DataRow ship = adapterPO.POData.PODetail[adapterPO.POData.PODetail.Rows.Count - 1];
	ship["Company"] = "NET";
	ship["PONUM"] = po;
	ship["POLine"] = j;
	ship["LineDesc"] = Convert.ToString(DescI);
	ship["CalcOurQty"] = 1000;
	ship["OrderQty"] = Convert.ToDecimal(1000);
	ship["XOrderQty"] = Convert.ToDecimal(1000);
	ship["QtyOption"] = "Our";
	ship["IUM"] = Convert.ToString(IUMI);
	ship["PUM"] = Convert.ToString(IUMI);
	ship["PartNum"] = Convert.ToString(PartI);
	ship["CommentText"] = Convert.ToString(CommentI);
	ship["ClassID"] = "FAB";
	ship["VendorNum"] = vend;
	ship["DueDate"] = DateTime.Now;
	ship["BaseUOM"] = "EA";
	ship["RcvInspectionReq"] = 1;
	adapterPO.Update();

The error I get is:

“A valid qty is required”

It wants me to put a qty in to “CalcOurQty”, but that field does not actually exist in the PODetail table. I am trying to put it in the “OrderQty” and “XOrderQty”, but no luck. I have seen that this is an issue on the DMT side as well, and the fix they have is to change “OrderQty” to “CalcOurQty”. Can’t seem to figure it out. Any ideas?

CalcOurQty exists on the DataView though. There must be some logic behind it. Have you tried populating it there before you update?

I have seen that it exists on the form, that is what drives me crazy. My theory is that it is referencing the qty from the release table. The issue is that this customization is not running from the PO form. We have a dashboard that lists all items that need to be Subcontracted for the week. The idea is that they can select the record, and click a button that generates a PO for the Subcontract operation.

Oh, now that’s interesting… I wonder if you added the CalcOurQty field to the DataView on your dashboard (just the DataView, not a UDF) and populated it if it would work… I’ve never ran into this problem before, so I’ve never tried it.

Change the quantity with the BO, don’t do it by setting it in the view. do something like this.

var qty = Convert.ToDecimal(1000);

adapterPO.ChangeDetailCalcOurQty(qty , po);

that works for me, you should also do this before the update, but you most likely know that :slight_smile:

3 Likes

oooooh! Getting closer! How much of this is necessary? Also, it keeps giving me an error saying that the subcontract operation 0 is invalid, yet I am setting the operation to 60. here is the Code:

					POAdapter adapterPO = new POAdapter(this.oTrans);
					adapterPO.BOConnect();

					adapterPO.GetByID(po);
					adapterPO.GetNewPODetail(po);
					adapterPO.ChangeDetailCalcOurQty(Convert.ToDecimal(QtyI));
					adapterPO.ChangeDetailCalcVendQty(Convert.ToDecimal(QtyI));
					adapterPO.ChangeDetailTranType("PUR-SUB");
					adapterPO.ChangeDetailJobNum(Convert.ToString(JobI));
					adapterPO.ChangeDetailAssemblySeq(0);
					adapterPO.ChangeDetailJobSeq(60);

					DataRow ship = adapterPO.POData.PODetail[adapterPO.POData.PODetail.Rows.Count - 1];
					ship["Company"] = "NET";
					ship["PONUM"] = po;
					ship["POLine"] = j;
					ship["LineDesc"] = Convert.ToString(DescI);
					ship["OrderQty"] = Convert.ToDecimal(QtyI);
					ship["XOrderQty"] = Convert.ToDecimal(QtyI);
					ship["QtyOption"] = "Our";
					ship["IUM"] = Convert.ToString(IUMI);
					ship["PUM"] = Convert.ToString(IUMI);
					ship["PartNum"] = Convert.ToString(PartI);
					ship["CommentText"] = Convert.ToString(CommentI);
					ship["ClassID"] = "FAB";
					ship["VendorNum"] = vend;
					ship["DueDate"] = DateTime.Now;
					ship["BaseUOM"] = "EA";
					ship["RcvInspectionReq"] = 1;
					adapterPO.Update();

When I set PO’s I just use these methods from BO:

GetNewPODetail
ChangeDetailPartNum
ChangeDetailCalcOurQty
ChangeUnitPrice
Update

In that order. Your demands may be different, but for some BO’s you need to set the parameters first, so try setting the sequence number of 60 first, then do: adapterPO.ChangeDetailJobSeq(60);

Do a trace and you can see when submitting ChangeDetailJobSeq the fields that are required to be completed before running that method.

I guess that is where I get lost. I have been checking the trace, but it doesn’t really reveal anymore info to me. This is the error I keep getting:

Description: Invalid SubContract Operation: 0.
Program: Erp.Services.BO.PO.dll
Method: PODetailBeforeUpdate

It almost looks like it is not setting the value of the operation at all.

Sometimes they don’t that is why I said you must set the 60 first then run that BO, or after it possibly. Also try just setting your Sequence, and not using that BO, sometimes they are not needed.

What do you mean by set the 60 first? Can you give me an example?

like how you do this. Do same thing for seq num. then try the BO, and if you get error try without BO.

I assume it’s looking for a valid SUB op since you told this above. Is op 60 a subcontract?

Also, order of operations maybe an issue. You can try setting the job seq before the asm seq, etc. Debug in VS might help you see whats happening.

That did work! I have a new set of errors to play with, but it is at least creating the line with the correct job, op, and asm. I didn’t think I could call out those fields like that since they technically don’t exist in the PODetail table.

Chris, yes it is valid, what Matthis1337 mentioned above worked for the job, asm, and op.

I am going to try to figure out this next set of issues, that way I don’t keep bothering y’all. I may be back monday with more questions haha. Thanks for the help so far!

Be sure to mark a response as a solution so others know what to do in future. Also remember you are just dealing with a dataset and a BO. They aren’t confined to rules of a table. You can build as many tables as you want in a dataset, and then the BO can submit it and built it accordingly. Not saying this happens everywhere, but for some yes.

Hi Aaron,
I know this is an old post, but I’m hopeful you’ll see this. In the traces I’ve run, I can see the methods you mentioned. I’m trying to use them in a custom code of a function.
This is my code, below. It doesn’t create new PO lines and it doesn’t throw any errors (when I test from REST call / swagger).

for(int i = 0; i < poLines; i++)
{
  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.GetNewPODetail(ref output, poNum);
  });
  
  string partNum = input.PODetail[i].PartNum;
  Guid sysRowID = output.PODetail[i].SysRowID;
  bool outBool;

  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.ChangeDetailPartNum(  
      ref partNum, sysRowID, "", false, out outBool, ref output);    
  });
  
  decimal orderQty = input.PODetail[i].OrderQty;
  
  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.ChangeDetailCalcOurQty(orderQty, ref output);    
  });
  
  string confirmMsg = "";
  output.PODetail[i].UnitCost = input.PODetail[i].UnitCost;
 
 /*
  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.ChangeUnitPriceConfirmOverride(ref output, out confirmMsg);    
  });
  */
  
  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.ChangeUnitPrice(ref output);    
  });
  
  this.CallService<Erp.Contracts.POSvcContract>(cs => {
    cs.Update(ref output);    
  });
 
} // end for loop

My “output” variable is a POTableset.

I have so many questions, but the main question is what am I doing wrong to create a PO line?
I’m also wondering how do these methods know which PO line is being created or modified?
ChangeDetailPartNum
ChangeDetailCalcOurQty
ChangeUnitPrice

I would so appreciate any help or guidance!
Thanks,

1 Like