Skip to main content
Solved

Detail Info from Graph Not Populating on Create


Hello,

Please see below for action script to create a new issue. I successfully pass over header level information (the only field I have mapped is description, everything else defaults). However, it is not populating my detail rows from the foreach loop. Any reason this might be happening?

This script is placed as an extension to the ProjectEntry class and the table that I’m selecting from is the project inventory w/ lotserial numbers. I have also confirmed that this particular ProjectID has two lines that would be created on a successful action execution.

Any help would be greatly appreciated!

        #region Actions

public PXAction<PMProject> createIssue;
PXUIField(DisplayName = "Create Issue", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
PXButton]
protected virtual IEnumerable CreateIssue(PXAdapter adapter)
{
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();

INRegister header = new INRegister();

//header.BranchID = Base.ProjectProperties.Current.DefaultBranchID;
//header.DocType = ;
//header.SiteID = ;
//header.TranDate = ;
//header.FinPeriodID = ;
//header.OrigModule = ;
header.TranDesc = Base.ProjectProperties.Current.Description;

if (graph.issue.Insert(header) == null)
{
return adapter.Get();
};

foreach (PXResult<PMLotSerialStatus> res in PXSelect<PMLotSerialStatus, Where<PMLotSerialStatus.projectID, Equal<Current<PMProject.contractID>>, And<PMLotSerialStatus.qtyAvail, NotEqual<decimal0>>>>.Select(graph))
{
PMLotSerialStatus LSS = res;

INTran newline = new INTran();

newline.BranchID = Base.ProjectProperties.Current.DefaultBranchID;
newline.InventoryID = LSS.InventoryID;
newline.SiteID = LSS.SiteID;
newline.LocationID = LSS.LocationID;
newline.ProjectID = LSS.ProjectID;
newline.Qty = LSS.QtyAvail;
newline.LotSerialNbr = LSS.LotSerialNbr;

if (graph.transactions.Insert(newline) == null)
{
return adapter.Get();
};
};

PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Popup);

return adapter.Get();

}

#endregion

 

Hi @rhooper91 

Make sure you have unique row values given the INTran DAC key

string docType, string refNbr, int? lineNbr

lineNbr is controlled by the header field INRegister.lineCntr

 

 


@Leonardo Justiniano Thank you for your suggestion! I tried adding LineNbr = header.LineCntr in the INTran container, assuming that when it gets created the assigned key value can be get, but I’m still getting the same behavior. I referenced some of the in-house code and they don’t update the docType and/or refNbr in some of them. Is it really required? Updated code below- I optimized a couple of other things as well.

        #region Actions

public PXAction<PMProject> createIssue;
>PXUIField(DisplayName = "Create Issue", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
>PXButton]
protected virtual IEnumerable CreateIssue(PXAdapter adapter)
{
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();

INRegister header = new INRegister()
{
//BranchID = Base.ProjectProperties.Current.DefaultBranchID;
//DocType = ,
//SiteID = ;
//TranDate = ;
//FinPeriodID = ;
//OrigModule = ;
//RefNbr = ,
//LineCntr = ,
TranDesc = Base.ProjectProperties.Current.Description
};

if (graph.issue.Insert(header) == null)
{
return adapter.Get();
};

foreach (PXResult<PMLotSerialStatus> res in PXSelect<PMLotSerialStatus, Where<PMLotSerialStatus.projectID, Equal<Current<PMProject.contractID>>, And<PMLotSerialStatus.qtyAvail, NotEqual<decimal0>>>>.Select(graph))
{
PMLotSerialStatus LSS = res;

INTran newline = new INTran()
{
TranType = SQLConstants.TranType,
LineNbr = header.LineCntr,
BranchID = Base.ProjectProperties.Current.DefaultBranchID,
InventoryID = LSS.InventoryID,
SiteID = LSS.SiteID,
LocationID = LSS.LocationID,
ProjectID = LSS.ProjectID,
UOM = SQLConstants.UoM,
Qty = LSS.QtyAvail,
LotSerialNbr = LSS.LotSerialNbr
};

if (graph.transactions.Insert(newline) == null)
{
return adapter.Get();
};
};

PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Popup);

return adapter.Get();

}

 


Hi @rhooper91  I made some changes to your code, can you please try with the below and verify?

    #region Actions

public PXAction<PMProject> createIssue;
PXUIField(DisplayName = "Create Issue", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
PXButton]
protected virtual IEnumerable CreateIssue(PXAdapter adapter)
{
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();

INRegister header = new INRegister();
header.TranDesc = Base.ProjectProperties.Current?.Description;
graph.issue.Current = header;
graph.issue.Update(graph.issue.Current);

foreach (PMLotSerialStatus LSS in PXSelect<PMLotSerialStatus, Where<PMLotSerialStatus.projectID, Equal<Current<PMProject.contractID>>,
And<PMLotSerialStatus.qtyAvail, NotEqual<decimal0>>>>.Select(graph))
{
INTran newline = (INTran)graph.transactions.Cache.Insert();

newline.BranchID = Base.ProjectProperties.Current?.DefaultBranchID;
newline.InventoryID = LSS.InventoryID;
newline.SiteID = LSS.SiteID;
newline.LocationID = LSS.LocationID;
newline.ProjectID = LSS.ProjectID;
newline.Qty = LSS.QtyAvail;
newline.LotSerialNbr = LSS.LotSerialNbr;
graph.transactions.Update(newline);
};

PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Popup);
return adapter.Get();
}
#endregion

 


Hey @Naveen Boga - thank you for taking the time to review and edit the script. I just inserted your script in lieu of mine and it is still acting the same way. See below for image of popup. The description is updating, like before, but no transaction rows are being added.

I have also included what the PXSelect should be returning from the visible grid I have on the project as a tab.

 

 


Hi, @rhooper91  Sorry, I have not tested the above code. Let me check from my end and let you know if I found anything.


@Naveen Boga No problem at all, you are doing this as a favor! Please see attached for the customization project.. if it helps. I had to enable project inventory and receive a couple of serialized items into the project to be able to get the grid to populate.


Hi, @rhooper91  I have verified with the above code and it is working fine.

The reason for not displaying the records in the Issues screen grid is that I don’t have any records in the PMLotSerialStatus table.

For that, I have given some hard-coded values and verified and it is working fine.

 

I do not see any issue with the code, please check PMLotSerialStatus table.

 #region Actions

public PXAction<PMProject> createIssue;
PXUIField(DisplayName = "Create Issue", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
PXButton]
protected virtual IEnumerable CreateIssue(PXAdapter adapter)
{
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();

INRegister header = new INRegister();
header.TranDesc = Base.ProjectProperties.Current.Description;
graph.issue.Current = header;
graph.issue.Update(graph.issue.Current);

//foreach (PMLotSerialStatus LSS in PXSelect<PMLotSerialStatus, Where<PMLotSerialStatus.projectID, Equal<Current<PMProject.contractID>>,
// And<PMLotSerialStatus.qtyAvail, NotEqual<decimal0>>>>.Select(graph))
//{
INTran newline = (INTran)graph.transactions.Cache.Insert();

newline.BranchID = Base.ProjectProperties.Current.DefaultBranchID;
newline.InventoryID = 691;
newline.SiteID = 154;
newline.LocationID = 155;
newline.ProjectID = Base.Project.Current.ContractID;
newline.Qty = 2;
// newline.LotSerialNbr = LSS.LotSerialNbr;
graph.transactions.Update(newline);
// };

PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.Popup);
return adapter.Get();
}
#endregion

 

 


Hey @Naveen Boga I had a feeling that the foreach was not doing what it was supposed to do. Thanks for doing the work to confirm. I’ll do some more digging and figure out how to get that to work and respond here if I make any progress. Thanks!


@Naveen Boga One thing that I’m finding is that I can’t utilize .Select(this) .. it forces me to use .Select(graph) which I don’t think is right. All the examples that I see in the source code use ‘this’. Maybe I’m just not understanding the logic correctly but it wouldn’t make sense to select the graph that I intend to place data into. Any thoughts? Below is the validation error when I try to do it.

 


Hi @rhooper91 I have modified that query in my above post. Please modify and verify. once.

 

foreach (PMLotSerialStatus LSS in PXSelect<PMLotSerialStatus, Where<PMLotSerialStatus.projectID, Equal<Current<PMProject.contractID>>, 
And<PMLotSerialStatus.qtyAvail, NotEqual<decimal0>>>>.Select(graph))
{

//logic here

}

 


@Naveen Boga Yeah, I plugged that in from last night and today again and still no success. I have a sneaking suspicion that it just isn’t finding records in the foreach due to incorrect logic so it never enters the loop. At the end of the statement, the .Select(graph) doesn’t seem right to me. I just used it because it was the only thing the validator allowed without barking at me. The graph that I defined is an INIssueEntry graph. I feel like I would need to define a PMLotSerialStatus graph (if that is even possible..) to store that information and then use that graph in my foreach statement. Ideally, I would use .Select(this) because that’s what nearly every query I see uses, but it gives me an error (see above in prior comment).

Again, I’m fairly new to this.. so I’m just running on speculation and trial and error at this point.


@Naveen Boga Ok.. I took a different approach and it worked. Instead of re-creating a view that I had already established on a project tab, I just used that view in my foreach loop. See below for revised snippet. ProjectInventory is the view I created.

foreach (PMLotSerialStatus LSS in ProjectInventory.Select())

Thanks for all your help! 

 


Reply