Return Material to Stock from a job with C#

hey all, I recently asked for help for writing code to issue material from stock to a job in c#, and got that working. However, I now need code that returns material from a job, back to stock. Below is the working code for issuing material from stock to a job:

private void issuemtl(PartInfo thePart,string job,decimal Qty, string oper)
	{ 
	   IssueReturnAdapter ia = new IssueReturnAdapter(oTrans);
       ia.BOConnect();

       string msg;
       bool reqInput;
       string lgl;
       string partTran;

       ia.GetNewIssueReturnToJob(job, 0, "STK-MTL", Guid.NewGuid(), out msg);
       //ia.get
       Erp.BO.IssueReturnDataSet.IssueReturnRow row = ia.IssueReturnData.IssueReturn[0];
       row.FromWarehouseCode = "MSC";
       row.FromBinNum = "CRIB";
	   row.ToBinNum = "PROD-IN";
       row.ToJobNum = job;
       row.ToWarehouseCode = "FST";
	   row.TranReference = "Operator: " + oper;

       row.ToJobPartNum = thePart.PartNum;
       row.ToJobSeqPartNum = thePart.PartNum;
       row.ToJobSeq = thePart.MtlSeq;  //has to be valid seq            
			
	   row.PartNum = thePart.PartNum;
       //row.FromAssemblyPartNum = thePart.PartNum;
    		
	   row.PartIUM = thePart.UOM;        
	   row.DimCode = thePart.UOM;
       row.DUM = thePart.UOM;
       row.UM = thePart.UOM;

       row.TranQty = Qty;
       row.RowMod = "U";
       ia.PrePerformMaterialMovement(out reqInput);
       ia.PerformMaterialMovement(true, out lgl, out partTran);
	}

This is my modified code for Returning material from a job to stock:

	private void unissuemtl(PartInfo thePart,string job,decimal Qty, string oper)
	{ 
	   IssueReturnAdapter ia = new IssueReturnAdapter(oTrans);
       ia.BOConnect();

       string msg;
       bool reqInput;
       string lgl;
       string partTran;

       ia.GetNewIssueReturnFromJob(job, 0, "STK-MTL", Guid.NewGuid());
       //ia.get
       Erp.BO.IssueReturnDataSet.IssueReturnRow row = ia.IssueReturnData.IssueReturn[0];
       row.ToWarehouseCode = "MSC";
       row.ToBinNum = "CRIB";
	   row.FromBinNum = "PROD-IN";
       row.FromJobNum = job;
       row.FromWarehouseCode = "FST";
	   row.TranReference = "Operator: " + oper;

       row.FromJobPartNum = thePart.PartNum;
       row.FromJobSeqPartNum = thePart.PartNum;
       row.FromJobSeq = thePart.MtlSeq;  //has to be valid seq            
			
	   row.PartNum = thePart.PartNum;
       //row.FromAssemblyPartNum = thePart.PartNum;
    		
	   row.PartIUM = thePart.UOM;        
	   row.DimCode = thePart.UOM;
       row.DUM = thePart.UOM;
       row.UM = thePart.UOM;

       row.TranQty = (-1) * Qty;
       row.RowMod = "U";

       ia.PrePerformMaterialMovement(out reqInput);
       ia.PerformMaterialMovement(true, out lgl, out partTran);
	}

I figured I could just switch the “GetNewIssueReturnToJob” to “GetNewIssueReturnFromJob”, and change the data that is being inputted, but it seems to want to use the same variables as the code for “GetNewIssueReturnToJob”. What I mean by this is that I keep getting an error that says “Valid ToJobNum is required”. If I use the same exact code as the issuematerial function, but change the module to “GetNewIssueReturnFromJob”, then it works, but it issues a positive qty to the job. Any suggestions on how to get this working?

Try turning on tracing and do the transaction in the user interface then read through the trace log to see what methods and data is called. Sometimes it is not obvious how to do something but the trace will tell you.

Cheers
Brett

1 Like

Try using this instead:
public void GetNewIssueReturn(string pcTranType, Guid pcMtlQueueRowID, string pCallProcess, IssueReturnDataSet ds)

Are you saying to use GetNewIssueReturn in place of GetNewIssueReturnToJob? If that is the case, what am I putting in for string pCallProcess? I tried running the code, and got “A valid MtlQeue RowIdent is required”.

I figured it out. Really really REALLY dumb. What drives me crazy is when you look in Epicor at transaction types, It only uses STK-MTL. However, in the adapter, in order to have it go from job to stock, I had to change the transaction type to “MTL-STK”, and it worked. Really stupid. If the backend code references the transaction type “MTL-STK”, why doesn’t the front end as well?!?!?! anyways, here is my working code for this:

private void unissuemtl(PartInfo thePart,string job,decimal Qty, string oper)
	{ 
	   IssueReturnAdapter ia = new IssueReturnAdapter(oTrans);
       ia.BOConnect();

       string msg;
       bool reqInput;
       string lgl;
       string partTran;

       ia.GetNewIssueReturnFromJob(job, 0, "MTL-STK", Guid.NewGuid());
       //ia.get
       Erp.BO.IssueReturnDataSet.IssueReturnRow row = ia.IssueReturnData.IssueReturn[0];
       row.ToWarehouseCode = "MSC";
       row.ToBinNum = "CRIB";
	   row.FromBinNum = "PROD-IN";
       row.FromJobNum = job;
       row.FromWarehouseCode = "FST";
	   row.TranReference = "Operator: " + oper;

       row.FromJobPartNum = thePart.PartNum;
       row.FromJobSeqPartNum = thePart.PartNum;
       row.FromJobSeq = thePart.MtlSeq;  //has to be valid seq            
			
	   row.PartNum = thePart.PartNum;
       //row.FromAssemblyPartNum = thePart.PartNum;
    		
	   row.PartIUM = thePart.UOM;        
	   row.DimCode = thePart.UOM;
       row.DUM = thePart.UOM;
       row.UM = thePart.UOM;

       row.TranQty = (-1) * Qty;
       row.RowMod = "U";
       ia.PrePerformMaterialMovement(out reqInput);
       ia.PerformMaterialMovement(true, out lgl, out partTran);
	}
2 Likes

Nice - I am glad you got it working because I completely forgot about this thread!