Skip to main content

I have created a custom screen called Material Reques Note (MRN). I need to add two button which crate an Issue and a Transfer base on the MRN data. When trying to create an INTran DAC instance for each inventory item in the MRN it does not works. According to the investigations did by me I assumes that INTran type instance did not initiated correctly. I hope that may need to Set more field values. Following is my action code for one button.
 

        public PXAction<MRMaterialRequest> CreateIssue;
PXButton(DisplayOnMainToolbar = true, CommitChanges = true)]
PXUIField(DisplayName = "Create Issue", Enabled = true)]
protected virtual IEnumerable createIssue(PXAdapter adapter)
{
MRMaterialRequest mrn = MaterialRequestView.Current;
PXResultset<MRInventoryItems> items = MaterialDetailsView.Select();

PXLongOperation.StartOperation(this,
() => CreateIssueDoc(mrn, items)
);
return adapter.Get();
}

public static void CreateIssueDoc(MRMaterialRequest mrn, PXResultset<MRInventoryItems> items)
{

using (var ts =new PXTransactionScope())
{
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();

INRegister issue = new INRegister()
{
TranDesc = "Issue created for MRN - " + mrn.RefNbr,
};
graph.issue.Insert(issue);
graph.issue.Update(issue);
graph.Actions.PressSave();
graph.issue.Current = issue;

int index = 1;
foreach (MRInventoryItems item in items)
{

INTran iNTran = new INTran()
{
InventoryID = item.InventoryID,
Qty = item.ReceivedQty,
DocType = "I",
LineNbr = index,
TranType = INTranType.Issue,
BranchID = 16,
SiteID = 154,
LocationID = item.ToLocationID
};

graph.transactions.Insert(iNTran);
graph.Save.Press();

issue.LineCntr = index;
graph.issue.Insert(issue);
graph.issue.Update(issue);
graph.Save.Press();

}

ts.Complete();
}
}

The hardcoded fields (BranchID etc..) values are exits in the system. What is the correct way to initiate an INTran instance?

Hi @PDharmasena10 

 

You could also use an IEnumerable for the actions:

public PXAction<SOOrder> CreateNCRAction;
/PXButton]
/PXUIField(DisplayName = "Create NCR", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
protected virtual IEnumerable createNCRAction(PXAdapter adapter)
{
var orderEntry = PXGraph.CreateInstance<SOOrderEntry>();
if( orderEntry == null)
{
return adapter.Get();
}

var gilMaint = PXGraph.CreateInstance<GilcrestMaint>();
var order = Base.CurrentDocument.Current;
var header = gilMaint.ISORecords.Insert();
header.DocType = "NCR";
header.SOOrderNbr = order.OrderNbr;
header.CustomerID = order.CustomerID;
gilMaint.ISORecords.Update(header);

var ncrDetail = gilMaint.NCRs.Insert();
ncrDetail.CustomerPONbr = order.CustomerOrderNbr;
gilMaint.NCRs.Update(ncrDetail);
gilMaint.Actions.PressSave();

SOOrderISOExt orderExt = PXCache<SOOrder>.GetExtension<SOOrderISOExt>(order);
header.DocNumber = orderExt.UsrNCRNumber;
orderEntry.CurrentDocument.Update(order);

orderEntry.Actions.PressSave();


PXRedirectHelper.TryRedirect(gilMaint, PXRedirectHelper.WindowMode.New);

return adapter.Get();

}

For your method also, in your foreach, you could use a data view rather than a ResultSet e.g., Base.YourView.Select() for the purpose of cycling through a grid.

 

Hope this helps, 

Aleks


Here the basic issue is the primary keys are not set correctly.
 


Could you share your DAC please @PDharmasena10 


Reply