How to customize Acumatica string field into stringlist? - acumatica

I am trying to customize the CustRefNbr field on the sales order entry screen to be a stringlist by overriding in the SOOrderEntry code. However, I am getting error:
\App_RuntimeCode\SOOrderEntry.cs(55): error CS0103: The name 'CustomerRefNbr' does not exist in the current context
#region CustomerRefNbr
[PXDBString(40, IsUnicode = true)]
[PXUIField(DisplayName = "External Reference")]
[PXStringList(
new string[]
{
CustomerRefNbr.Email,
CustomerRefNbr.Phone,
CustomerRefNbr.Web,
CustomerRefNbr.Notification
},
new string[]
{
"Email",
"Phone",
"Web",
"Notification"
})]
protected virtual void SOOrder_CustomerRefNbr_CacheAttached(PXCache cache)
{
}
#endregion

Never mind. Forgot to add this part:
public static class CustomerRefNbr
{
public const string Email = "EMAIL";
public const string Phone = "PHONE";
public const string Web = "WEB";
public const string Notification = "NOTIFICATION";
}

Related

Adding Customer Class to GLTran \ GLTranR to see in screen GL404000 (Account Details)

I am currently trying to add the customer account class to the viewing area of the GL404000 screen with the by extending the GLTran DAC.
The AccountID, AccountCD and Account name are already available so I thought it would be an easy task.
In GLTranR, I saw where they were pulling in the account data:
public new abstract class referenceID : PX.Data.BQL.BqlInt.Field<referenceID> { }
[PXDBInt()]
[PXDimensionSelector("BIZACCT", typeof(Search<BAccountR.bAccountID>), typeof(BAccountR.acctCD), DescriptionField = typeof(BAccountR.acctName), DirtyRead = true)]
[PXUIField(DisplayName = CR.Messages.BAccountCD, Enabled = false, Visible = false)]
public override Int32? ReferenceID
{
get
{
return this._ReferenceID;
}
set
{
this._ReferenceID = value;
}
}
The line that I attempted to change to my need was the [PXDimensionSelector()] however I cannot get this to pull in the class data. Even when I dont change the code at all it will not populate the column.
public new abstract class usrBusinessAccountClass : PX.Data.BQL.BqlInt.Field<usrBusinessAccountClass> { }
protected Int32? _UsrBusinessAccountClass;
[PXDBInt()]
[PXDimensionSelector("BIZACCT", typeof(Search<BAccountR.bAccountID>), typeof(BAccountR.acctCD), DescriptionField = typeof(BAccountR.acctClass), DirtyRead = true)]
[PXUIField(DisplayName = "Business Account Class", Enabled = false, Visible = false)]
public virtual Int32? UsrBusinessAccountClass
{
get {return _UsrBusinessAccountClass;}
set{ _UsrBusinessAccountClass = value;} // set does work but value does not???
}
just for a test I changed the setter to:
set { _UsrBusinessAccountClass = 1234; }
And that populated the column with the value 1234, so that is why I think my issue is just with selecting the class.
I would show this but I need 10 rep to post images.
You are on the proper track. The following code shows how to retrieve additional data to display within the screen.
Non-Database backed field on the DAC you wish to display data on :
public sealed class GLTranRExtension : PXCacheExtension<GLTranR>
{
public abstract class usrClassID : BqlString.Field<usrClassID>
{
}
[PXString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
[PXSelector(typeof(CRCustomerClass.cRCustomerClassID), DescriptionField = typeof(CRCustomerClass.description))]
[PXUIField(DisplayName = "Business Account Class")]
public string UsrClassID { get; set; }
}
Graph extension in which the extension field is then populated with data :
public class AccountByPeriodEnqExtension : PXGraphExtension<AccountByPeriodEnq>
{
protected virtual void __(Events.RowSelecting<GLTranR> e)
{
if(e.Row is GLTranR row)
{
GLTranRExtension rowExt = row.GetExtension<GLTranRExtension>();
using(new PXConnectionScope())
{
BAccount bAccount = PXSelectReadonly<BAccount, Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(this.Base, row.ReferenceID);
if(bAccount != null)
{
rowExt.UsrClassID = bAccount.ClassID;
}
}
}
}
}
You will also need to add within the GL404000 the UI elements for your new extension fields. The result will look as follows :

Dynamic Input mask using the county DAC on the customer screen

Good day
I am trying to set my Input mask at runtime according to the country that is selected.
I created the following DAC to save the Input mask:
namespace PX.Objects.CS
{
public class CountryExt : PXCacheExtension<PX.Objects.CS.Country>
{
#region UsrPhoneMask
[PXDBString(50)]
[PXUIField(DisplayName="Phone Mask")]
public virtual string UsrPhoneMask { get; set; }
public abstract class usrPhoneMask : PX.Data.BQL.BqlString.Field<usrPhoneMask> { }
#endregion
}
}
The part I am struggling with is when I Override the attribute on-screen level, this is the Phone1 field on the Customer screen:
namespace PX.Objects.AR
{
public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
#region Event Handlers
[PXDBString(50, IsUnicode = true,
InputMask = Search<CountryExt.usrPhoneMask, Where<Country.countryID,Equal<Current<Country.countryID>>>>]
[PXUIField(DisplayName = "Phone 1", Visibility = PXUIVisibility.SelectorVisible)]
// [PhoneValidation()]
[PXMassMergableField]
[PXPersonalDataField]
protected virtual void Contact_Phone1_CacheAttached(PXCache cache){ }
}
}
I know it is the search I am implementing wrong just don't know how to fix it.
I have also tried setting it using a const
public const string Masknum = PXSelect<CountryExt.usrPhoneMask, Where<Country.countryID, Equal<Current<Country.countryID>>>>;
public class masknum : PX.Data.BQL.BqlString.Constant<masknum>
{
public masknum() : base(Masknum) {; }
}
PXSelect<CountryExt.usrPhoneMask, Where<Country.countryID,Equal<Current<Country.countryID>>>>;
[PXDBString(50, IsUnicode = true, InputMask = Masknum)]
[PXUIField(DisplayName = "Phone 1", Visibility = PXUIVisibility.SelectorVisible)]
// If you do not remove below attribute the mask will not be set
// [PhoneValidation()]
// [PXMassMergableField]
[PXPersonalDataField]
protected virtual void Contact_Phone1_CacheAttached(PXCache cache)
{
}
Property values declared in DAC attribute are not dynamic because they are required to be constant values by .NET Framework compilers. To change the mask at runtime you should investigate the ReturnState property of CacheAttached and FieldSelecting events.
From the Source Code page (SM204570) you can search for the OrderSiteSelectorAttribute which implements a dynamic mask using these methods.
Other examples shipped in the product source code might be more useful for your use case so you can also do a broad search for ReturnState. Here's the relevant code shown in the screenshot above:
public override void CacheAttached(PXCache sender)
{
base.CacheAttached(sender);
PXDimensionAttribute attr = new PXDimensionAttribute(SiteAttribute.DimensionName);
attr.CacheAttached(sender);
attr.FieldName = _FieldName;
PXFieldSelectingEventArgs e = new PXFieldSelectingEventArgs(null, null, true, false);
attr.FieldSelecting(sender, e);
_InputMask = ((PXSegmentedState)e.ReturnState).InputMask;
}
public override void SubstituteKeyFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
base.SubstituteKeyFieldSelecting(sender, e);
if (_AttributeLevel == PXAttributeLevel.Item || e.IsAltered)
{
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, null, null, null, null, null, _InputMask, null, null, null, null);
}
}
EDIT:
From the matching DAC RowSelected event, try calling the SetInputMask method.
If that is producing the expected results it is the most straightforward way to achieve dynamic input mask:
PXStringAttribute.SetInputMask<DAC.field>(sender, inputMaskValue);

Need help in selector control

I created a selector control which displays a list of all serial #s from INItemLotSerial table, it works fine, the problem is the description field is showing InventoryID, how to show InventoryCD. Please have a look at below sample code.
[PXSelector(typeof(Search<INItemLotSerial.lotSerialNbr>),
new Type[] { typeof(INItemLotSerial.lotSerialNbr), typeof(INItemLotSerial.inventoryID) },
SubstituteKey = typeof(INItemLotSerial.lotSerialNbr), DescriptionField = typeof(INItemLotSerial.inventoryID))]
// i also joined with InventoryItem but this doesn't works.
[PXSelector(typeof(Search2<INItemLotSerial.lotSerialNbr,
LeftJoinSingleTable<InventoryItem, On<InventoryItem.inventoryID,Equal<INItemLotSerial.inventoryID>>>>),
new Type[] { typeof(INItemLotSerial.lotSerialNbr), typeof(INItemLotSerial.inventoryID) },
SubstituteKey = typeof(INItemLotSerial.lotSerialNbr), DescriptionField = typeof(InventoryItem.inventoryCD))]
The main problem with DescriptionField property is that it is waiting for getting the field from the same table for which Selector is written. But in the case of ID/CD usually, the CD is not present in the table where ID is present, except the main table.
UPDATED I have removed previous code (implementation using custom attributes and FieldSelecting event handler) because of the performance issues which it is bringing with it. The code below is resulting with the same lookup but getting the data with one inner join instead of all the requests which the previous code was doing.
You can do the following to get this lookup with description:
Create a PXProjection on INItemLotSerial and InventoryItem tables like below:
[PXCacheName("Lot Serials with Inventory CD")]
[PXProjection(typeof(Select2<INItemLotSerial,
InnerJoin<InventoryItem,
On<INItemLotSerial.inventoryID, Equal<InventoryItem.inventoryID>>>>))]
public class INItemLotSerialWithInventoryItem : IBqlTable
{
[PXDBInt(BqlField = typeof(INItemLotSerial.inventoryID))]
[PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
public virtual int? InventoryID { get; set; }
public abstract class inventoryID : IBqlField { }
[PXDBString(InputMask = "", IsUnicode = true, BqlField = typeof(InventoryItem.inventoryCD))]
[PXUIField(DisplayName = "Inventory ID")]
public virtual string InventoryCD { get; set; }
public abstract class inventoryCD : IBqlField { }
[PXDBString(InputMask = "", IsUnicode = true, BqlField = typeof(INItemLotSerial.lotSerialNbr))]
[PXUIField(DisplayName = "Lot/Serial Nbr")]
public virtual string LotSerialNbr { get; set; }
public abstract class lotSerialNbr : IBqlField { }
}
Set your selector to use this PXProjection like below:
[PXSelector(typeof(Search<INItemLotSerialWithInventoryItem.lotSerialNbr>),
new Type[] { typeof(INItemLotSerialWithInventoryItem.lotSerialNbr) },
SubstituteKey = typeof(INItemLotSerialWithInventoryItem.lotSerialNbr),
DescriptionField = typeof(INItemLotSerialWithInventoryItem.inventoryCD))]
As a result, you will get lookup like below:

Acumatica Processing Screen Updating ARTran Custom Field Needs To Also Update Custom Table field

We have a custom processing screen that is updating a custom field called UsrDateNotified in the ARTran table where the UsrDateNotified is prior to the RevisionDateReceived in a custom table ItemBaseDocument. We also need to update the UsrDateNotified field in table ItemBaseDocument which is linked to the InventoryID in ARTran. Our current code below validates for updating the ARTran table, but we are struggling with how to also update the related ItemBaseDocument for the selected ARTran records. What is the right approach for this scenario?
using System;
using System.Collections;
using System.Linq;
using PX.Data;
using PX.SM;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.IN;
namespace DocCenter
{
public class UpdateLastNotified : PXGraph<UpdateLastNotified>
{
public PXFilter<UpdateLastNotifiedFilter> MasterView;
public PXCancel<UpdateLastNotifiedFilter> Cancel;
[PXFilterable]
public PXSelect<ARTran> DetailsView;
public UpdateLastNotified()
{
Cancel.SetCaption("Clear Filter");
this.DetailsView.Cache.AllowInsert = false;
this.DetailsView.Cache.AllowDelete = false;
this.DetailsView.Cache.AllowUpdate = true;
}
protected virtual IEnumerable detailsView()
{
UpdateLastNotifiedFilter filter = MasterView.Current as UpdateLastNotifiedFilter;
PXSelectBase<ARTran> cmd = new PXSelectJoinOrderBy<ARTran,
InnerJoin<InventoryItem, On<ARTran.inventoryID, Equal <InventoryItem.inventoryID>>,
InnerJoin<ItemBaseDocument, On<InventoryItemExt.usrDocumentNumber, Equal<ItemBaseDocument.baseDocumentCode>>,
InnerJoin<Contact, On<ARTranExt.usrContactID, Equal<Contact.contactID>>>>>,
OrderBy<Asc<ARTran.tranDate>>>(this);
cmd.WhereAnd<Where<ContactExt.usrNotificationPriority,
Equal<Current<UpdateLastNotifiedFilter.notificationPriority>>>>();
cmd.WhereAnd<Where<ARTranExt.usrDateNotified,
Less<ItemBaseDocument.revisionDateReceived>>>();
if (filter.BaseDocumentCode != null)
{
cmd.WhereAnd<Where<InventoryItemExt.usrDocumentNumber,
Equal<Current<UpdateLastNotifiedFilter.baseDocumentCode>>>>();
}
return cmd.Select();
}
public PXAction<UpdateLastNotifiedFilter> Process;
[PXProcessButton]
[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Process")]
protected virtual IEnumerable process(PXAdapter adapter)
{
PXLongOperation.StartOperation(this, delegate()
{
foreach(ARTran tran in DetailsView.Select())
{
if (tran.Selected==true)
{
ARTranExt tranExt = tran.GetExtension<ARTranExt>();
ARInvoiceEntry tranEntry = new ARInvoiceEntry();
tranExt.UsrDateNotified = MasterView.Current.DateNotified;
tranEntry.Transactions.Update(tran);
tranEntry.Save.PressButton();
}
}
}
);
return adapter.Get();
}
[Serializable]
public class UpdateLastNotifiedFilter : IBqlTable
{
public static class NotificationPriority
{
public const string None = "N";
public const string Alert = "A";
public const string Express = "E";
public const string Shipment = "P";
public const string Subscription = "S";
}
#region NotificationPriority
public abstract class notificationPriority : PX.Data.IBqlField
{
}
[PXDBString(1, IsFixed = true)]
[PXDefault(NotificationPriority.None)]
[PXUIField(DisplayName = "Notification Type")]
[PXStringList(
new string[]
{
NotificationPriority.None,
NotificationPriority.Alert,
NotificationPriority.Express,
NotificationPriority.Shipment,
NotificationPriority.Subscription
},
new string[]
{
"None",
"Alert",
"Express",
"Shipment",
"Subscription"
})]
#endregion
#region BaseDocumentID
public abstract class baseDocumentCode : PX.Data.IBqlField
{
}
[PXString(50)]
[PXUIField(DisplayName="Document Number")]
[PXSelector(typeof(DocCenter.ItemBaseDocument.baseDocumentCode))]
public virtual String BaseDocumentCode
{
get;
set;
}
#endregion
#region DateNotified
public abstract class dateNotified : PX.Data.IBqlField
{
}
[PXDBDate()]
[PXDefault(typeof(AccessInfo.businessDate))]
[PXUIField(DisplayName = "Date Notified")]
public DateTime? DateNotified { get; set; }
#endregion
}
}
}
Your best bet would be to create a view that selects ItemBaseDocument.
PXSelect<ItemBaseDocument> ViewName;
In your for loop of your action button, you will want to create a new ItemBaseDocument object and set it equal to the corresponding ItemBaseDocument row entry. You can then update the date of this object, and when you execute your Save.PressButton() action, that should save the updates to that entry as well.
foreach(ARTran tran in DetailsView.Select())
{
if (tran.Selected==true)
{
ARTranExt tranExt = tran.GetExtension<ARTranExt>();
ARInvoiceEntry tranEntry = new ARInvoiceEntry();
tranExt.UsrDateNotified = MasterView.Current.DateNotified;
tranEntry.Transactions.Update(tran);
tranEntry.Save.PressButton();
//Target Added Code
ItemBaseDocument doc = PXSelect<ItemBaseDocument, Where<ItemBaseDocument.inventoryID,
Equal<Required<ARTran.inventoryID>>>>.Select(tran.InventoryID);
doc.UsrDateNotified = MasterView.Current.DateNotified;
}
}
Disclaimer: There may be a syntax error in the added code above. If there is, please let me know and I will fix it.

Acumatica - Need underscores in my email addresses

I have a field in my customization that I've set to [PXDBEmail] Unfortunately, this field replaces entered underscores with a space. Is there a way to keep it from doing so?
Update - DAC code below
public abstract class customerID : PX.Data.IBqlField
{
}
protected string _CustomerID;
[PXDBEmail]
[PXUIField(DisplayName = "User Name")]
public virtual string CustomerID
{
get
{
return this._CustomerID;
}
set
{
this._CustomerID = value != null ? value.Trim() :null;
}
}
Out of the box, the Email field on the Customers screen accept undercores without any issues:
Could you please compare the decalration of your custom field with the declaration of the EMail field from the Contact DAC?
public partial class Contact : IBqlTable, IContactBase, IAssign, IPXSelectable, CRDefaultMailToAttribute.IEmailMessageTarget
{
...
#region EMail
public abstract class eMail : PX.Data.IBqlField { }
private string _eMail;
[PXDBEmail]
[PXUIField(DisplayName = "Email", Visibility = PXUIVisibility.SelectorVisible)]
[PXMassMergableField]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual String EMail
{
get { return _eMail; }
set { _eMail = value != null ? value.Trim() : null; }
}
#endregion
...
}
Turns out my ASPX had a PXMaskEdit field instead of a PXTextEdit Field. Strange one!
Thanks for all the input.

Resources