Solved

Not able to add values on fieldDeaulting event


Userlevel 2
Badge

I am trying to fetch value from DB in FieldDefaulting event but the value is not reflected in the UI.

This my code in graph extension.

protected void SOShipment_UsrPickListPrintNumber_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (SOShipment)e.Row;
SOPickingWorksheetReview tempGraph = PXGraph.CreateInstance<SOPickingWorksheetReview>();

SOPickingWorksheet txsetup = PXSetup<SOPickingWorksheet>.Select(tempGraph);
SOPickingWorksheetExt rowExt = PXCache<SOPickingWorksheet>.GetExtension<SOPickingWorksheetExt>(txsetup);
e.NewValue = 100;
}

DACExtension

#region Virtual fields
[PXInt()]
[PXUIField(DisplayName = "# of times Pick list printed", Required = false, Enabled = false)]
public int? UsrPickListPrintNumber { get; set; }
public abstract class usrPickListPrintNumber : PX.Data.BQL.BqlInt.Field<usrPickListPrintNumber> { }
#endregion

 

icon

Best answer by Naveen Boga 1 July 2022, 11:44

View original

12 replies

Userlevel 7
Badge +17

Hi, @param2022  Couple of observations from the code.

  1. You created an Unbound field i.e. UsrPickListPrintNumber
  2. In the Filed Defaulting event, you have created a graph instance i.e. SOPickingWorksheetReview is NOT required. You can you Base graph in the Select statement.
  3. You have extended the DAC SOPickingWorksheetExt, but nowhere assigning the value from this DAC.
Userlevel 2
Badge

@Naveen Boga I know I need to use the DACExtension but value from that extension was not consistent so i added static 100 so i can have same effect on every record. Can you please tell me why UI is not showing the 100 value ?

Userlevel 7
Badge +17

@param2022  Have you added COMMITCHANGES = true at .aspx page?

Userlevel 2
Badge

@Naveen Boga i have set that field in screen editor do i need to do it in ASPX too ?

Userlevel 7
Badge +17

@param2022  That should be fine. While creating the Shipment is fielddefaulting event invoked and are you able to debug this code?

Userlevel 2
Badge

@Naveen Boga Is fielddefaulting event only invoked while creating a record? I need to show this field for all the records. It is a read-only field I need to add it for all the created records also. And I am able to debug the code when the view is being loaded.

Userlevel 5
Badge +1

@param2022  Yes, FieldDefaulting event invoked while creating a record. For existing you can write a script to update those records. 

 

Userlevel 2
Badge

@Vinay Koppula @Naveen Boga I need to show that field from the another table so I have created a non-bounded field. I cannot add that to SOShipment table. Any other way possible ??

Userlevel 7
Badge +17

Hi, @param2022  Since you wanted to go with the Unbound field.

You can write the logic in the FieldSelecting event instead FieldDeafulting event.

 

protected void SOShipment_UsrPickListPrintNumber_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
var row = (SOShipment)e.Row;
SOPickingWorksheetReview tempGraph = PXGraph.CreateInstance<SOPickingWorksheetReview>();

SOPickingWorksheet txsetup = PXSetup<SOPickingWorksheet>.Select(tempGraph);
SOPickingWorksheetExt rowExt = PXCache<SOPickingWorksheet>.GetExtension<SOPickingWorksheetExt>(txsetup);
e.ReturnValue = 100;
}

 

Userlevel 5
Badge +1

@param2022 as Naveen indicated FieldSelecting event should work for your requirement. 

Userlevel 2
Badge

@Naveen Boga @Vinay Koppula I have used this method and my values are getting the value but in each and every Shipment I get first record only. I tried to add query but it doesn’t seem to work any idea how can we do that ??

 

SOPickingWorksheetReview tempGraph = PXGraph.CreateInstance<SOPickingWorksheetReview>();
SOPickingWorksheetShipment worksheetShippingSetup = PXSetup<SOPickingWorksheetShipment>.Select(tempGraph);
SOPickingWorksheet temp = (from p in tempGraph.Select<SOPickingWorksheet>()
join q in tempGraph.Select<SOPickingWorksheetShipment>() on p.WorksheetNbr equals q.WorksheetNbr
where q.ShipmentNbr == row.ShipmentNbr
select p)?.FirstOrDefault();

 

Userlevel 7
Badge +17

@param2022  Here is the code.

 protected void SOShipment_UsrPickListPrintNumber_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
var row = (SOShipment)e.Row;
if (row != null)
{
SOPickingWorksheetShipment worksheetShippingSetup = PXSetup<SOPickingWorksheetShipment>.Select(Base);
//SOPickingWorksheet temp = (from p in tempGraph.Select<SOPickingWorksheet>()
// join q in tempGraph.Select<SOPickingWorksheetShipment>() on p.WorksheetNbr equals q.WorksheetNbr
// where q.ShipmentNbr == row.ShipmentNbr
// select p)?.FirstOrDefault();

SOPickingWorksheet temp = PXSelectJoin<SOPickingWorksheet, InnerJoin<SOPickingWorksheetShipment,
On<SOPickingWorksheetShipment.worksheetNbr, Equal<SOPickingWorksheet.worksheetNbr>>>,
Where<SOPickingWorksheetShipment.shipmentNbr, Equal<Required<SOPickingWorksheetShipment.shipmentNbr>>>>
.Select(Base, row.ShipmentNbr).FirstTableItems.ToList().FirstOrDefault();
}
}

 

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