Solved

Enabling a custom field in the PO Details grid on a closed PO

  • 2 August 2023
  • 5 replies
  • 112 views

Userlevel 6
Badge +3

In 2023R1

I have a custom field UsrOriginalPromise to the Purchase Orders Details.  I am enabling all three fields shown below for closed orders.

Requested Date is the Requested field with a modified label.  Current Promise is Promised with a modified label.  Those are built in fields that I am able to get enabled for editing.

I added all three fields to the Closed Workflow.  I also added the following code to finish the job of enabling the cache and enabling the fields: THIS IS IN THE PROJECT EDITOR, NOT VS.

If I remove the comments from the lines below, the two built in fields get enabled, but the custom field does not, AND there are errors on the PO3010PL entry point screen and in the Project editor.

  public class POOrderEntry_Extension : PXGraphExtension<PX.Objects.PO.POOrderEntry>
{
#region Event Handlers
protected void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if(InvokeBaseHandler != null) InvokeBaseHandler(cache, e);
var row = (POLine)e.Row;

//POLineExt itemExt = PXCache<POLine>.GetExtension<POLineExt>(row);
//if (itemExt == null) return;

Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<POLine.requestedDate>(cache, row, true);
PXUIFieldAttribute.SetEnabled<POLine.promisedDate>(cache, row, true);
//PXUIFieldAttribute.SetEnabled<POLineExt.usrOriginalPromise>(cache, row, true);
}
#endregion
}

If I remove the // from JUST the the line that gets a reference to the extension, it will publish.  But if you do that and try to open PO3010PL (entry point for PO’s), you get this error:

 

In the project Editor, if you click on the screen ID to edit the screen, you get this error:

To make sure my syntax was correct, I created a library in VS.  I just added this code into the extension

		protected void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if (InvokeBaseHandler != null) InvokeBaseHandler(cache, e);
var row = (POLine)e.Row;

POLineExt itemExt = PXCache<POLine>.GetExtension<POLineExt>(row);
if (itemExt == null) return;

Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<POLineExt.usrOriginalPromise>(cache, row, true);
}

If I add this library to the site, the custom field gets enabled.  However, you still get the error on the entry point screen and in the project editor.

If you go directly to the PO301000 screen and lookup a PO, it works and all three fields are editable.

In summary, if I use a VS library to enable the custom field, it works, but causes errors on the entry point screen and in the project editor.

I uploaded the project if anyone wants to see the entire project.

Very strange.

 

 

 

icon

Best answer by Zoltan Febert 2 August 2023, 01:00

View original

5 replies

Userlevel 6
Badge +3

You get a null ref exception on this line:

POLineExt itemExt = PXCache<POLine>.GetExtension<POLineExt>(row);

I would suggest to replace it with this:

var itemExt = row?.GetExtension<POLineExt>();

 

Userlevel 7
Badge +5

I feel like changing the row from a var to POLine and then directly call .GetExtention should work.

      POLine row = (POLine)e.Row;
POLineExt itemExt = row.GetExtension<POLineExt>();

Which I now see is essentially what zfebert56 suggested. :)

Userlevel 6
Badge +3

@zfebert56 That fixed it.

OK...I’m going to try to be professional here. Is Acumatica framework “moody?”????

I’ve been using that syntax on over 40 projects over the last 5 years.  It is the exact same syntax as in the training courses.

Why the hell does it work on all my other projects and not this one?  I wasted 4 hours yesterday changing code, publishing, WAITING, REPEAT.

What gives here?  I am seriously angry here.  In desperation, I even tried putting the code in a VS library. My code compiled in VS, actually WORKED as intended on the PO screen, but caused an error on the entry point screen AND in the project editor when the site referenced my library.

Just insane.

 

EDIT: is this a 2023R1 thing perhaps?  There should be SOME reason for this.

Userlevel 6
Badge +3

@Joe Schmucker

There is no magic there, you just simple forgot to check if row was null or not. I did the null check with “row?.”, but this one also should work:

	  if (row == null) return; 	
POLineExt itemExt = PXCache<POLine>.GetExtension<POLineExt>(row);
if (itemExt == null) return;

 

Userlevel 6
Badge +3

@zfebert56 OMG!  How did I not see that. 

I would like to recall my rant.  Please forgive my previous post.  

What an idiot I am.  I cannot believe I missed that.  I think that I went down the rabbit hole searching for an error somewhere else and after all that time, I became inadvertently blind to the obvious.

Thank you so much for pointing this out.  I am so grateful.  I deserve a demotion in my ranking.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved