Acumatica Custom Selector SQL Error - Incorrect Syntax near the keyword - acumatica

I am trying to create a custom Parts selector to search all records if there is no vendor selected, if a vendor is selected I want to filter the selector's results to only include Parts with the vendor selected.
Using PXCustomSelectorAttribute:
SQL Error: Incorrect syntax near the keyword 'AND'
Incorrect syntax near the keyword 'ORDER'
[PXNonInstantiatedExtension]
public class SO_SOLine_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOLine>
{
#region InventoryID
[PXMergeAttributes(Method = MergeMethod.Replace)] //was append
[PXUIField(DisplayName = "Part #")]
[PartSelector(typeof(SOLineExt.usrCusVendor))]
public int? InventoryID { get; set; }
#endregion
}
public class PartSelector : PXCustomSelectorAttribute
{
[Serializable]
[PXProjection(typeof(
Select2<atcVendorItem,
LeftJoin<InventoryItem,
On<InventoryItem.inventoryCD, Equal<atcVendorItem.inventoryCD>, And<InventoryItem.inventoryID, Equal<atcVendorItem.inventoryID>>>>>), Persistent = false)]
public class atcPartView : IBqlTable
{
// DAC W/Inventory Item Table mapped and joined with Vendor Items
}
//Selected table
private Type _MfgField;
////way to have multiple description fields
public PartSelector(Type MfgField) : base(typeof(atcPartView.inventoryID))
{
_MfgField = MfgField;
}
protected virtual IEnumerable GetRecords()
{
var cache = this._Graph.Caches[BqlCommand.GetItemType(_MfgField)];
var cbs = (BAccount)cache.Current;
// make mfgfield
if (cbs != null)
{
foreach (atcPartView p in PXSelect<atcPartView, Where<atcPartView.vendorID, Equal<Required<SOLineExt.usrMfg>>>>.Select(_Graph, cbs.BAccountID))
{
yield return p;
}
}
else
{
foreach (atcPartView p in PXSelect<atcPartView, Where<atcPartView.vendorID, IsNotNull>>.Select(_Graph))
{
yield return p;
}
}
}
}

I was able to find another exception while debugging in visual studio,
my issue was because I was trying to cast the field as BAccount when referencing the SOLine Extension. Changing the cast fixed my issue

Related

How to get Selector Substitute Key / Description values

Lets say I have a DAC record, like SOOrder, and I have a field like customerID, where there is a PXSelectorAttribute defined on an integer field, that has a SubstitueKey = typeof(Customer.acctCD) and Description = typeof(Customer.acctName). Is there some way that I can get the values of the substitute key / description field for that record without doing a PXSelect against the selectors table?
Thanks
-Kyle
Note since no version was specified my example was coded against 2020r2
The following is an example that updates an Invoice/Memo's Description to the Location's CD and Descr fields [CD: Descr] when the location is changed on the Invoice/Memo. I believe the function you're looking for is PXSelectorAttribute.Select<SELECTOR_FIELD>(SELECTOR_FIELD_CACHE, SELECTOR_FIELD_RECORD) AS SELECTOR_TARGET_DAC.
public class ArInvoiceEntrySoExt : PXGraphExtension<ARInvoiceEntry>
{
#region Event Handlers
#region ArInvoice
public virtual void _(Events.FieldUpdated<ARInvoice.customerLocationID> e, PXFieldUpdated del)
{
var inv = e.Row as ARInvoice;
del?.Invoke(e.Cache, e.Args);
if (inv != default)
{
var loc = PXSelectorAttribute.Select<ARInvoice.customerLocationID>(e.Cache, inv) as Location;
e.Cache.SetValueExt<ARInvoice.docDesc>(inv, string.Format("{0}: {1}", loc?.LocationCD, loc?.Descr));
}
}
#endregion
#endregion
}
An alternative, you can use PXSelectorAttribute.GetField(SELECTOR_FIELD_CACHE, SELECTOR_FIELD_RECORD, "SELECTOR_FIELD_NAME", SELECTOR_FIELD_VALUE, "SELECTOR_TARGET_FIELD_NAME") to get a specific field from the selector's target record. As an example, the following code does the same thing as above using this alternative method:
public class ArInvoiceEntrySoExt : PXGraphExtension<ARInvoiceEntry>
{
#region Event Handlers
#region ArInvoice
public virtual void _(Events.FieldUpdated<ARInvoice.customerLocationID> e, PXFieldUpdated del)
{
var inv = e.Row as ARInvoice;
del?.Invoke(e.Cache, e.Args);
if (inv != default)
{
var loc = PXSelectorAttribute.Select<ARInvoice.customerLocationID>(e.Cache, inv) as Location;
e.Cache.SetValueExt<ARInvoice.docDesc>(inv, string.Format("{0}: {1}",
PXSelectorAttribute.GetField(e.Cache, inv, "customerLocationID", inv.CustomerLocationID, "LocationCD"),
PXSelectorAttribute.GetField(e.Cache, inv, "customerLocationID", inv.CustomerLocationID, "Descr")));
}
}
#endregion
#endregion
}
I also was told about another method that can be used
PXFieldState.UnwrapValue(object value) will return the UI equivalent of a value in the back end. This is nice because then you can use one method for both drop downs and selectors, but I cant seem to see how to get the description field using this

How to get DAC record from Note Table

Does anyone have a code snippet on how to go from RefNoteId => DAC when I dont know what dac type the note is attached to?
I have made it this far (row.RefNoteID is what I am starting from)
Note note = PXSelect<Note, Where<Note.noteID, Equal<Required<Note.noteID>>>>.Select(this, row.RefNoteID);
Type recordType = Type.GetType(note.EntityType);
PXCache recordCache = Caches[recordType];
How can I now do a PXSelect<recordType, Where<recodType.noteID, Equal<Required<recordType.noteID>>>>.Select(GRAPH) ? The recordType could be any DAC in the system that has a noteID.
Thanks
The below code works for me and it is based on the way Acumatica gets the record inside the PXRefNoteSelectorAttribute.PrimaryRow_RowPersisted.
The problem with this approach is that this will work for Header entities like SOOrder, INRegister, SOInvoice, SOShipment, and others. But for "detail" entities like SOLine, INTran, and others this approach will work only if that corresponding record has some Note related to Text/File. Acumatica is adding records corresponding to their NoteID into the Note table only if that detail records have some Note/Text. My best guess is that this is done in order to avoid over-spamming the Note table.
using PX.Data;
using PX.Objects.SO;
using System;
using System.Collections;
using System.Linq;
using System.Web.Compilation;
namespace SearchByNoteID
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> searchByNoteID;
[PXUIField(DisplayName ="Search by Note ID")]
[PXButton(CommitChanges = true)]
public virtual IEnumerable SearchByNoteID(PXAdapter adapter)
{
var order = adapter.Get<SOOrder>().FirstOrDefault();
if(order!=null)
{
//
//...
//
Guid? noteID = GetNoteID();
object record = GetRecordByNoteID(noteID);
//
//... do whatever you want with the record
//
}
return adapter.Get();
}
protected object GetRecordByNoteID(Guid? noteID)
{
var type = GetEntityType(this.Base, noteID);
if(type==null) return null;
object entityRow = new EntityHelper(this.Base).GetEntityRow(type, noteID);
return entityRow;
}
protected Type GetEntityType(PXGraph graph, Guid? noteID)
{
if (noteID == null)
{
return null;
}
Note note = PXSelectBase<Note, PXSelect<Note, Where<Note.noteID, Equal<Required<Note.noteID>>>>.Config>.SelectWindowed(graph, 0, 1, new object[]
{
noteID
});
if (note == null || string.IsNullOrEmpty(note.EntityType))
{
return null;
}
return PXBuildManager.GetType(note.EntityType, false);
}
}
}

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

Button not showing in the UI

I'm extending the AccountByPeriodEnq logic, I just want to add a button on top of my screen to modify the selected GL records but it just doesnt want to show up and I can't figure out why.
Here's my code :
namespace PX.Objects.GL
{
class AccountByPeriodEnqExtensions : PXGraphExtension<AccountByPeriodEnq>
{
#region Actions
public PXAction<AccountByPeriodFilter> Letter;
[PXUIField(Visible = true, DisplayName = "Lettrer")]
[PXButton(CommitChanges = true)]
protected virtual IEnumerable letter(PXAdapter adapter)
{
IReadOnlyCollection<GLTranR> selectedTrans = GetSelectedTrans();
if (selectedTrans.Any())
{
PXLongOperation.StartOperation(this, delegate ()
{
foreach(GLTranR line in selectedTrans)
{
// UpdateSomeFieldsAndPersists
}
});
}
else
{
throw new PXException("Error");
}
return Base.Filter.Select();
}
#endregion
#region Utility
private IReadOnlyCollection<GLTranR> GetSelectedTrans()
{
return Base.GLTranEnq.Cache.Updated
.Cast<GLTranR>()
.Where(tran => tran.Selected == true)
.ToArray();
}
#endregion
}
}
Is there anything I'm missing here ?
Regards,
Edit:
To clarify i'm trying to customize the GL404000, Account Details. And using the inspector I saw the Business logic is in the AccountByPeriodEnq Graph
Using Acumatica Inspect Element feature notice that the 'Account by Period' screen (GL402000) is not using the 'AccountByPeriodEnq' graph.
It is using the 'AccountHistoryByYearEnq' graph instead so that's the graph you want to target:
You also need to declare Actions on the primary DAC of that Graph.
The one for 'AccountHistoryByYearEnq' is a little bit harder to find than usual.
You can use Acumatica Source Code page and search for 'PXPrimaryGraph(typeof(AccountHistoryByYearEnq)':
In this case it is AccountByYearFilter DAC that you should use:
[System.SerializableAttribute()]
[PXCacheName(Messages.Account)]
[PXPrimaryGraph(typeof(AccountHistoryByYearEnq), Filter = typeof(AccountByYearFilter))]
public partial class Account : PX.Data.IBqlTable, PX.SM.IIncludable
{
[…]
}
I think this is a special case for Filter, when there's no filter Account would have been the DAC to use for the Actions.
Now that you have identified the Primary Graph of the Screen (AccountHistoryByYearEnq) and the Primary DAC of the Graph (AccountByYearFilter) it should work as expected:
public class AccountByPeriodEnq_Extension : PXGraphExtension<AccountHistoryByYearEnq>
{
public PXAction<AccountByYearFilter> letter;
[PXUIField(DisplayName = "Letter")]
[PXButton]
protected virtual IEnumerable Letter(PXAdapter adapter)
{
return adapter.Get();
}
}
UI:
EDIT:
For Account detail page (GL404000), use the same code with different DAC and Graph:
using PX.Data;
using System.Collections;
namespace PX.Objects.GL
{
public class AccountByPeriodEnq_Extension : PXGraphExtension<AccountByPeriodEnq>
{
#region Actions
public PXAction<AccountByPeriodFilter> letter;
[PXUIField(DisplayName = "Letter")]
[PXButton]
protected virtual IEnumerable Letter(PXAdapter adapter)
{
return adapter.Get();
}
#endregion
}
}
With a base Acumatica install that's all that is needed for the Action to appear:
Note that you can specify explicit state and view rights for the button control, though I don't think your issue is related to access rights if you're working in a developer instance:
[PXUIField(DisplayName = "Letter",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select)]
I finally found my problem, I missed the public member for my class.
namespace PX.Objects.GL
{
public class AccountByPeriodEnqExtensions : PXGraphExtension<AccountByPeriodEnq>
{
#region Actions
public PXAction<AccountByPeriodFilter> Letter;
Thanks for your answer HB, i'll reuse it.

Acumatica Scan barcode

In Acumatica project , on Receipt screen have a lookup button "Add Item". When Inventory lookup show dialog ( it's FromDetail template ), i will scan barcode from my bill. But, i must scan second times it to working.
How can i to filter grid details and set checked a row filtered according barcode ? And how can to know row count filtered? . Please help me.
The below figure illustrates.
snip code
Screen Receipt
You will be in a much better position with FieldVerifying handler implemented as follows for the INSiteStatusFilter.BarCode field to split scanned barcode and assign the new values both to BarCode field (though the PXFieldVerifyingEventArgs.New property) and custom unbound FilterQtySelected field. Then inside the FieldUpdated handler you will select all records from the detail grid, that satisfy filter condition and set Qty. Selected according to your unbound FilterQtySelected field:
public class INReceiptEntryExt : PXGraphExtension<INReceiptEntry>
{
public class INSiteStatusFilterExt : PXCacheExtension<INSiteStatusFilter>
{
#region QtySelected
public abstract class filterQtySelected : PX.Data.IBqlField
{
}
[PXQuantity]
public virtual decimal? FilterQtySelected { get; set; }
#endregion
}
public void INSiteStatusFilter_BarCode_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
{
var barCode = (string)e.NewValue;
string[] codes = barCode.Split(';');
decimal qtySelected;
if (codes.Length == 3 && decimal.TryParse(codes[2], out qtySelected))
{
e.NewValue = codes[1];
sender.GetExtension<INSiteStatusFilterExt>(e.Row).FilterQtySelected = qtySelected;
return;
}
sender.GetExtension<INSiteStatusFilterExt>(e.Row).FilterQtySelected = null;
}
public void INSiteStatusFilter_BarCode_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
INSiteStatusFilter filter = e.Row as INSiteStatusFilter;
var filterExt = filter.GetExtension<INSiteStatusFilterExt>();
if (string.IsNullOrEmpty(filter.BarCode) || !filterExt.FilterQtySelected.HasValue) return;
foreach(INSiteStatusSelected record in Base.sitestatus.Select())
{
record.Selected = true;
record.QtySelected = sender.GetExtension<INSiteStatusFilterExt>(e.Row).FilterQtySelected;
Base.sitestatus.Update(record);
}
}
}
You will need to add your custom 2D format support on the existing barcode infrastructure screens via a customization project.

Resources