Why is my hyperlink / button in the grid to launch a screen disabled? - acumatica

I have a customization to the Sales Orders screen, where I've added a user field (non-bound / [PXString] to hold the value of a PO Receipt Nbr. I populate it with the RowSelected event, and I'm trying to launch the Purchase Receipts screen from that field with a PXAction tied to that field's Linked Command:
The Field:
public abstract class usrPOReceiptNbr : BqlString.Field<usrPOReceiptNbr> { }
[PXString(15, IsUnicode = true)]
[PXUIField(DisplayName = "PO Receipt Nbr", Enabled = true)]
public virtual string UsrPOReceiptNbr { get; set; }
The RowSelected event code to populate the field:
var soordershipment = e.Row as SOOrderShipment;
using (new PXConnectionScope())
{
//get the extension
var soordershipmentext = PXCache<SOOrderShipment>.GetExtension<SOOrderShipmentExt>(soordershipment);
//Get the soorder cache...
SOOrder soorder = Base.Document.Current;
if (soorder != null)
{
//Now get the POReceiptLine record:
PXResultset<POReceiptLine> res = PXSelectJoin<POReceiptLine,
InnerJoin<SOOrder,
On<SOOrder.orderNbr, Equal<POReceiptLine.sOOrderNbr>,
And<SOOrder.orderType, Equal<POReceiptLine.sOOrderType>>>>,
Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>,
OrderBy<Desc<POReceiptLine.receiptNbr>>>.Select(Base, soorder.OrderNbr);
foreach (PXResult<POReceiptLine> rec in res)
{
POReceiptLine porl = (POReceiptLine)rec;
soordershipmentext.UsrPOReceiptNbr = porl.ReceiptNbr;
break; //Stop after the first record, since I only want the highest sorted field
}
}
}
The code to launch the Purchase Receipts screen is as follows:
public PXAction<SOOrder> LaunchPurchaseReceipts;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Launch Purchase Receipts", Enabled = true)]
protected virtual IEnumerable launchPurchaseReceipts(PXAdapter adapter)
{
var soorder = (SOOrder)Base.Document.Current;
POReceiptEntry graph = PXGraph.CreateInstance<POReceiptEntry>();
var soordershipment = (SOOrderShipment)Base.shipmentlist.Current;
var soordershipmentext = PXCache<SOOrderShipment>.GetExtension<SOOrderShipmentExt>(soordershipment);
graph.Document.Current = graph.Document.Search<POReceipt.receiptNbr, POReceipt.receiptType>(soordershipmentext.UsrPOReceiptNbr, soordershipment.ShipmentType);
throw new PXRedirectRequiredException(graph, "Purchase Receipts")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
}
The problem is that I continue to get this error when launching the hyperlink on the PO Receipt Nbr field for that screen (it never even gets to the code to launch the screen):
...and here's the error...
I've tried forcing the field to enabled with the RowSelected event, using:
PXUIFieldAttribute.SetEnabled<SOOrderShipmentExt.usrPOReceiptNbr>(e.Cache, null, true);
But that doesn't do anything.
Any ideas?

This issue has been resolved with a suggestion from Brendan (thanks much) by using the RowSelected event to set the method's enabled property to true:
LaunchPurchaseReceipts.SetEnabled(true);

Related

How to activate the filtering action for a user field added to a grid

I have a customization to the Release Time Activities screen (EP507020) where I add a user field. This user field will contain the result of fetching the Appointment status from the Appointments screen (FS300200) based on the Appointment ID that I've also added to the Release Time Activities screen grid.
This was done so that the process grid could be filtered for appointment status that were a certain value. The Appointment Status User field I've added contains the same attributes that the Status field contains on the Appointments screen, with the Cache extension looking as follows:
#region UsrApptStatus
public abstract class usrApptStatus : IBqlField
{
}
[PXDBString(1)]
[FSAppointment.status.ListAtrribute]
[PXUIField(DisplayName = "Appt Status",Enabled = false)]
public virtual string UsrApptStatus { get; set; }
#endregion
This works fine when I fetch the status as follows in a Graph extension:
protected virtual void EPActivityApprove_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var epactivityapprove = (EPActivityApprove)e.Row;
if (epactivityapprove != null)
{
FSxPMTimeActivity rowExt = epactivityapprove.GetExtension<FSxPMTimeActivity>();
if (rowExt != null)
{
var appointmentID = rowExt.AppointmentID;
var fsappt = (FSAppointment)PXSelect<FSAppointment,
Where<FSAppointment.appointmentID, Equal<Required<FSAppointment.appointmentID>>>>.Select(Base, appointmentID);
var epactivityapproveext = PXCache<EPActivityApprove>.GetExtension<EPActivityApproveExt>(epactivityapprove);
epactivityapproveext.UsrApptStatus = fsappt.Status;
}
}
}
The problem is that when I go to filter the Status column, no matter what I choose from the list of options, it clears all rows. I have no idea why this wouldn't work, but I'm sure I'm missing something.
Grid before filtering:
Filter:
Grid after filter:
It seems to me that changing the value in the RowUpdated event is interfering with the filter. If you wrote both extensions, it would help to have both custom fields in the same extension and use the PXFormula attribute to set the value of your status based on the AppointmentID field. This way you wouldn't have to rely on the event:
#region UsrApptStatus
public abstract class usrApptStatus : IBqlField
{
}
[PXDBString(1)]
[FSAppointment.status.ListAtrribute]
[PXFormula(typeof(Selector<appointmentID, FSAppointment.status>))]
[PXUIField(DisplayName = "Appt Status",Enabled = false)]
public virtual string UsrApptStatus { get; set; }
#endregion

Load value from popup to InventoryID field

am generating a pop on one new button click in stock Items screen, inside popup have two buttons, user select some data from fields in the popup and then click on ok, then inventoryId should be formed with some special characters and then it should display in InventoryID field. I can form the InventoryID but unable to display it in InventoryID field.
[PXButton]
[PXUIField(DisplayName = "Generate")]
public virtual void GenerateInv()
{
InventoryItemExt ext = Base.Item.Cache.GetExtension<InventoryItemExt>(Base.Item.Current);
Base.Item.Current.InventoryCD = ext.UsrInvId;
Base.Item.Cache.Insert(Base.Item.Current);
}
I had this issue before,
and the following code was provided by acumatica. you may try the same.
here in the below code, inventoryCD contains the value, i wanted to set.
InventoryItem item = PXCache<InventoryItem>.CreateCopy(Base.Item.Current);
OrderedDictionary keys = new OrderedDictionary(StringComparer.OrdinalIgnoreCase)
{
{
typeof(InventoryItem.inventoryCD).Name,
adapter.View.Cache.GetValue(adapter.View.Cache.Current,
typeof(InventoryItem.inventoryCD).Name)
}
};
OrderedDictionary vals = new OrderedDictionary(StringComparer.OrdinalIgnoreCase)
{
{
typeof(InventoryItem.inventoryCD).Name, inventoryCD
}
};
adapter.View.Cache.Update(keys, vals);
if (adapter.Searches != null && adapter.Searches.Length > 0)
{
adapter.Searches[0] = inventoryCD;
}
return adapter.Get();
Also make sure your function have the correct input and the return type
IEnumerable GenerateInv(PXAdapter adapter)

Error when creating a Sales Order using the graph object

I'm trying to create a Sales Order from the PO screen using the SOOrderEntry graph object. I'm selecting the branch using a technique from another Stack Overflow case, and I continuously get the following error:
I can't figure out why this error is coming up, since I'm setting the CustomerID. Here's the code:
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
public override void Initialize()
{
Base.action.AddMenuAction(CreateSO);
}
public PXAction<POOrder> CreateSO;
[PXUIField(DisplayName = "Create Sales Order", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton]
protected virtual void createSO()
{
SOOrderEntry sograph = null;
SOOrder soorder = null;
SOLine soline = null;
//Let's get the current data from the screen we're in...
var poorder = (POOrder)Base.Document.Current;
PXResultset<POLine> res = PXSelect<POLine, Where<POLine.orderNbr, Equal<Required<POLine.orderNbr>>>>.Select(Base, poorder.OrderNbr);
using (PXLoginScope ls = new PXLoginScope("admin"))
{
//Create a new instance of the AP Bills screen graph..
sograph = PXGraph.CreateInstance<SOOrderEntry>();
//Get the branch...
var branch = (Branch)PXSelect<Branch, Where<Branch.branchCD, Equal<Required<Branch.branchCD>>>>.Select(Base, "WI-NVC VET");
//soorder.BranchID = branch.BranchID;
//This handler is added per RD from another Stack Overflow case. It's necessary to select the Branch...
sograph.FieldDefaulting.AddHandler<SOOrder.branchID>((s, e) =>
{
e.NewValue = branch.BranchID;
e.Cancel = true;
});
soorder = new SOOrder();
//The OrderType...
soorder.OrderType = SOOrderTypeConstants.SalesOrder;
sograph.Document.Insert(soorder);
soorder.OrderDate = (DateTime?)DateTime.Now;
soorder.RequestDate = (DateTime?)DateTime.Now;
//Get the customer id...
var bacct = (BAccountR)PXSelect<BAccountR, Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>.Select(Base, "NE-C003118");
soorder.CustomerID = bacct.BAccountID; // (int?)5454;
sograph.Document.Update(soorder);
sograph.Actions.PressSave();
This is very import to always assign the result of PXCache Insert or Update method invocation to some local variable so further you make changes to the object from the cache, rather than to a legacy record, which has nothing in common with PXCache.
The issue should be resolved by the following tiny change:
soorder = new SOOrder();
soorder.OrderType = SOOrderTypeConstants.SalesOrder;
soorder = sograph.Document.Insert(soorder);

Default PO Type to 'Drop Ship' not working properly

I'm trying to default the OrderType.POOrderType to POOrderType.DropShip. I've tried altering the attributes in the customization manager to the following:
[PXDBString(2, IsKey = true, IsFixed = true)]
[PXDefault(POOrderType.DropShip)]
[POOrderType.List()]
[PXUIField(DisplayName = "Type", Visibility = PXUIVisibility.SelectorVisible, Enabled = true)]
[PX.Data.EP.PXFieldDescription]
But upon insertion of a new record, it does nothing. I've also tried using the CacheAttached event in a graph extension of POOrderEntry as follows:
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
[PXDBString(2, IsKey = true, IsFixed = true)]
[PXDefault(POOrderType.DropShip)]
[POOrderType.List()]
[PXUIField(DisplayName = "Type", Visibility = PXUIVisibility.SelectorVisible, Enabled = true)]
[PX.Data.EP.PXFieldDescription]
protected virtual void POOrder_OrderType_CacheAttached(PXCache sender) { }
}
This also does NOT work.
I've finally tried using the RowInserting event as follows
protected virtual void POOrder_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
{
POOrder poorder = (POOrder)e.Row;
if (poorder == null) return;
poorder.OrderType = POOrderType.DropShip;
}
This DOES default to DropShip, however, when I use the dropdown on the screen to change back to 'Normal', it empties all the fields, and the Type is also empty. If I select Normal again, then it displays the data in the fields correctly. I can't figure out what's going on here. I always have to select the Type twice to get anything to show. I can't see why the RowInserting event would cause this behavior...
There is POOrder_OrderType_FieldDefaulting event in the POOrderEntry, where default order type is set.
protected virtual void POOrder_OrderType_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = POOrderType.RegularOrder;
}
It have 'higher priority' than PXDefault attribute (check T200 training for more information).
So you need to override this event handler.

Acumatica Extension on SOSitesStatusSelected

I've been having this problem on Acumatica extension for days now and can't seem to figure out the resolution. I've added an action on the Inventory Lookup Dialog of Sales Order screen (see screenshot below), the action is task to update the QtySelected to 1 and also to update my added Field which is the Brand to "testBrand". It is an extension of the SOSitesStatusSelected table, but whenever i clicked on the action, it only updates QtySelected and not my added Field Brand.
You may refer to my code below, thank you and I appreciate all the help.
//DAC
#region UsrBrand
[PXUIField(DisplayName = "Brand", Visible = true, Enabled = true)]
public virtual string UsrBrand{get;set;}
public abstract class usrBrand : IBqlField{}
#endregion
//BLC
public PXAction<PX.Objects.SO.SOOrder> updateAttributes;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Update Attributes")]
protected void UpdateAttributes()
{
this.Base.sitestatus.AllowInsert= true;
this.Base.sitestatus.AllowUpdate= true;
foreach (SOSiteStatusSelected line in this.Base.sitestatus.Select())
{
line.QtySelected = 1;
this.Base.sitestatus.Update(line);
SOSiteStatusSelectedExt rowExt = this.Base.sitestatus.Cache.GetExtension<SOSiteStatusSelectedExt>(line);
rowExt.UsrBrand = "testBrand";
this.Base.sitestatus.Cache.Update(rowExt);
}
}
In this case your extension SOSiteStatusSelectedExt is not a separate item. It's a part of the base record actually. So you don't need to update it separately.
line.QtySelected = 1;
SOSiteStatusSelectedExt rowExt = this.Base.sitestatus.Cache.GetExtension<SOSiteStatusSelectedExt>(line);
rowExt.UsrBrand = "testBrand";
this.Base.sitestatus.Update(line);

Resources