Skip to main content
Solved

How to fetch values from one dac to another screen?


Hello all,

I have a custom field, similar to stock item description in the stock items screen and I am looking to fetch the value from the custom field to my PO screen under the details tab. I have a new field added under the details tab & now want to display in this. How can I do that?

Thanks in advance.

11 replies

Userlevel 6
Badge +4

Hi @Harshita ,

You can use following code snippet to achieve the same.
 

 protected void POLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
if (row == null) return;

// Fetch the custom field value from the InventoryItem
InventoryItem inventoryItem = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, row.InventoryID);

InventoryItemExt inventoryItemExt = inventoryItem.GetExtension<InventoryItemExt>();

if (inventoryItemExt != null)
{
POLineExt rowExt = PXCache<POLine>.GetExtension<POLineExt>(row);
rowExt.UsrCustomField = inventoryItemExt.UsrCustomField;
}
}

Hope, it helps!
FYI: This code works only when you updating the Inventory ID field from POLine.

 

Userlevel 6
Badge +3

Hi @Harshita ,

You can use following code snippet to achieve the same.
 

 protected void POLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
if (row == null) return;

// Fetch the custom field value from the InventoryItem
InventoryItem inventoryItem = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, row.InventoryID);

InventoryItemExt inventoryItemExt = inventoryItem.GetExtension<InventoryItemExt>();

if (inventoryItemExt != null)
{
POLineExt rowExt = PXCache<POLine>.GetExtension<POLineExt>(row);
rowExt.UsrCustomField = inventoryItemExt.UsrCustomField;
}
}

Hope, it helps!
FYI: This code works only when you updating the Inventory ID field from POLine.

 

Hello @Dipak Nilkanth , thank you for your prompt response. It is throwing the below error:

 

Userlevel 6
Badge +4

Hi @Harshita ,

You are adding code to the DAC extension, this is not right. You can add custom fields to the DAC extension and not write an logic.

this code you need to add to the the graph. i.e. public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>

You need to extend POOrderEntry graph and add logic to transfer fields values from one screen to another.

 public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
{
protected void POLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
if (row == null) return;

// Fetch the custom field value from the InventoryItem
InventoryItem inventoryItem = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, row.InventoryID);

InventoryItemExt inventoryItemExt = inventoryItem.GetExtension<InventoryItemExt>();

if (inventoryItemExt != null)
{
POLineExt rowExt = PXCache<POLine>.GetExtension<POLineExt>(row);
rowExt.UsrCustomField = inventoryItemExt.UsrCustomField;
}
}
}

 

Userlevel 6
Badge +3

Hi @Harshita ,

You are adding code to the DAC extension, this is not right. You can add custom fields to the DAC extension and not write an logic.

this code you need to add to the the graph. i.e. public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>

You need to extend POOrderEntry graph and add logic to transfer fields values from one screen to another.

 public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
{
protected void POLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
if (row == null) return;

// Fetch the custom field value from the InventoryItem
InventoryItem inventoryItem = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, row.InventoryID);

InventoryItemExt inventoryItemExt = inventoryItem.GetExtension<InventoryItemExt>();

if (inventoryItemExt != null)
{
POLineExt rowExt = PXCache<POLine>.GetExtension<POLineExt>(row);
rowExt.UsrCustomField = inventoryItemExt.UsrCustomField;
}
}
}

 

Hey @Dipak Nilkanth , 
can you let me know what is the base graph that I shall select?

Userlevel 6
Badge +4

Hi @Harshita ,

POOrderEntry graph, you need to extend.

Userlevel 6
Badge +3

Hi @Harshita ,

POOrderEntry graph, you need to extend.

 

Userlevel 6
Badge +4

Hi @Harshita ,

Have you added custom field in the Inventory item DAC which you needed to pass to the POLine?

 

Userlevel 6
Badge +3

Hi @Harshita ,

Have you added custom field in the Inventory item DAC which you needed to pass to the POLine?

 

Yes, it is in other pkg

Userlevel 6
Badge +4

Then, you need to give reference of that package to include the InteventoryItemExt DAC. i.e. using AnotherPackageNamespaceName.

Userlevel 6
Badge +3

Then, you need to give reference of that package to include the InteventoryItemExt DAC. i.e. using AnotherPackageNamespaceName.

What if I add it under same pkg with your above code?

Userlevel 6
Badge +4

It will helpful to you, if you add custom field of InventoryItem DAC to the same package, So you do not need to give another package reference.

Reply