Why is my Overriden Field is not taking in effect, on CRActivityMaint - acumatica

I might seem lost, but I feel that my code is correct but it does not work. I implemented my own PXStringListAttribute, thus removing the base Attribute of existing PXStringListAttribute, but it seems not working.
[PXRemoveBaseAttribute(typeof(ActivityStatusListAttribute))]
[CustomStatusApproval]
[PXUIField(DisplayName="test")]
protected virtual void CRActivity_TimeActivity_ApprovalStatus_CacheAttached(PXCache cache)
{
}

The field you are trying to customize is PMTimeActivity.ApprovalStatus so your cache attached method name is not pointing to the correct reference to override the attributes.
Viewing the properties of the field you can see the dac and field you should use:
This results in the cache attached method name of PMTimeActivity_ApprovalStatus_CacheAttached (using the naming convention of DataClass_DataField_CacheAttached)
Here is a working example:
public class CRActivityMaintExtension : PXGraphExtension<PX.Objects.EP.CRActivityMaint>
{
[PXRemoveBaseAttribute(typeof(PX.Objects.CR.ActivityStatusListAttribute))]
[PXStringList(new[]
{
PX.Objects.CR.ActivityStatusListAttribute.Draft,
PX.Objects.CR.ActivityStatusListAttribute.Open,
PX.Objects.CR.ActivityStatusListAttribute.InProcess,
PX.Objects.CR.ActivityStatusListAttribute.Completed,
PX.Objects.CR.ActivityStatusListAttribute.Approved,
PX.Objects.CR.ActivityStatusListAttribute.Rejected,
PX.Objects.CR.ActivityStatusListAttribute.Canceled,
PX.Objects.CR.ActivityStatusListAttribute.PendingApproval,
PX.Objects.CR.ActivityStatusListAttribute.Released,
"T1",
"T2"
},
new[]
{
PX.Objects.EP.Messages.Draft,
PX.Objects.EP.Messages.Open,
PX.Objects.EP.Messages.InProcess,
PX.Objects.EP.Messages.Completed,
PX.Objects.EP.Messages.Approved,
PX.Objects.EP.Messages.Rejected,
PX.Objects.EP.Messages.Canceled,
PX.Objects.EP.Messages.Balanced,
PX.Objects.EP.Messages.Released,
"TEST1",
"TEST2"
})]
[PXUIField(DisplayName = "Some Test")]
protected virtual void PMTimeActivity_ApprovalStatus_CacheAttached(PXCache cache)
{
}
}

Related

View Delegate Building Correct SQL, Returning No Records

I have an inquiry screen in which we filter historical AP records from a custom DAC by a VendorID or FinPeriodID from the filter.
I've created a View Delegate to handle the dynamic filtering logic, and through debugging have confirmed that it's being hit correctly and is appending the proper WhereAnd statement with the current value of the Filter. Running the SQL statement equivalent directly in the database is returning the correct records, however the View Delegate ends up returning no records to the screen.
The base view is just defined as: public PXSelectReadonly<AAAPDoc> Docs;
The View Delegate is defined as:
protected virtual IEnumerable<AAAPDoc> docs()
{
AAAPHistoricalFilter filter = Filter.Current;
PXSelectBase<AAAPDoc> cmd = new PXSelectReadonly<AAAPDoc>(this);
if (filter.VendorID.HasValue)
{
cmd.WhereAnd<Where<AAAPDoc.vendorID, Equal<Current<AAAPHistoricalFilter.vendorID>>>>();
}
if (filter.FinPeriodID.HasValue)
{
cmd.WhereAnd<Where<AAAPDoc.finPeriodID, Equal<Current<AAAPHistoricalFilter.finPeriodID>>>>();
}
foreach (AAAPDoc record in cmd.Select())
{
yield return record;
}
}
Filter DAC
[Serializable]
[PXHidden]
public class AAAPHistoricalFilter : IBqlTable
{
#region VendorID
public abstract class vendorID : BqlInt.Field<vendorID>
{
}
[Vendor(IsDBField = false, DisplayName = "Vendor ID")]
public virtual int? VendorID { get; set; }
#endregion
...
Edit: Updated with original partial Filter DAC to give context to solution
Turns out, it was a problem with my filter DAC. I used the [Vendor] attribute with the property IsDBField = false. Removing the IsDbField property altogether from the attribute gave me the expected results.

Override base query in child graph is not calling

I am trying to override the Base DataView (bql) in my child Dac, but doesn't look like it doesn't override by child graph.
public class BaseBLC : PXGraph<BaseBLC, DAC>
{
public PXSelect<DAC> Objects;
}
public class BaseBLCExt : PXGraphExtension<BaseBLC>
{
// Overriding using this, but look like it doesn't
public PXSelectOrderBy<DAC,
OrderBy<Asc<DAC.field>>> Objects;
}
I am referring below link, am i doing anything wrong, I am trying to override shipment graph query and want append my own condition, how may i do this, One point is BaseData view is using current in query for filtering record.
Any help?
https://help-2018r1.acumatica.com/(W(10))/Wiki/ShowWiki.aspx?pageid=b1faf924-c742-4eb2-9a88-0fe299cf6137
Below code help to override the base DataView.
public class BaseBLCExt : PXGraphExtension<BaseBLC>
{
public PXSelectOrderBy<DAC,
OrderBy<Asc<DAC.field>>> Objects;
}
public class BaseBLCExtOnExt : PXGraphExtension<BaseBLCExt, BaseBLC>
{
protected IEnumerable objects()
{
return PXSelect<DAC>.Select(Base);
}
}

Acumatica : Switching Selector Attribute on the same DAC Field

Good Day!
I have a field in my DAC where I need to change the Selector attribute depending on the setup that I set on my preferences. As you may know, there is an existing LeadSelector Attribute and CustomerSelector Attribute on acumatica. I wish to change the selector attribute of that given field if I set Customer on my preferences, and vice versa.
Is there any available resources right here now?
I've been thinking of creating an Extended Selector attribute on which I will check what is the preference setup then inherit the LeadSelector or CustomerSelector on the Extended Selector. But I think it might not be possible.
The other thing that I've been thinking, is to add both selectors on the attribute and remove them from the graph level whenever which preference is set up.
I'm also thinking of creating 2 selectors, on which I will hide the other depending on the preference setup. But the problem is, the selector is being used not only on one page, and it's a hassle if I create 2 selectors just to solve that issue. And also in the future it might not just lead and customer selectors.
I hope you can help me, I'm out of ideas. Thank you so much.
UPDATE 09-24-2019
I created a custom selector attribute for Lead and Customer Selector attributes. And it's working just I want it to be, but now my problem is, the description field won't show on the text box or on that field, also, there are error such as 'Investor name cannot be found in the system'.
Investor Selector Attribute
public class InvestorSelectorAttribute : PXCustomSelectorAttribute
{
public InvestorSelectorAttribute() : base(typeof(REInvestor.accountID))
{
DescriptionField = typeof(REInvestor.acctName);
SubstituteKey = typeof(REInvestor.acctName);
}
protected IEnumerable GetRecords()
{
var leads = new PXSelect<Contact,
Where<Contact.contactType, Equal<ContactTypesAttribute.lead>,
Or<Where<Contact.contactType, Equal<ContactTypesAttribute.person>,
And<Contact.status, Equal<LeadStatusesAttribute.converted>>>>>>(this._Graph);
var contacts = new PXSelect<BAccountR>(this._Graph);
REFeature setup = PXSelect<REFeature>.Select(this._Graph);
if (setup.InvestorType == InvestorTypesAttribute.LeadVal)
{
foreach (Contact lead in leads.Select())
{
yield return new REInvestor { AccountID = lead.ContactID, AcctName = lead.DisplayName };
}
}
else
{
foreach (BAccountR contact in contacts.Select())
{
yield return new REInvestor { AccountID = contact.BAccountID, AcctName = contact.AcctName, AcctCD = contact.AcctCD };
}
}
}
}
Unbound REInvestor DAC
[Serializable]
[PXCacheName("Investor")]
public class REInvestor : IBqlTable
{
public abstract class accountID : BqlInt.Field<accountID> { }
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = REMessages.DisplayNames.AccountID, Visibility = PXUIVisibility.SelectorVisible)]
public virtual int? AccountID { get; set; }
public abstract class acctName : BqlString.Field<acctName> { }
[PXDBString(128, InputMask = "", IsUnicode = true)]
[PXUIField(DisplayName = REMessages.DisplayNames.AccountName, Visibility = PXUIVisibility.SelectorVisible)]
public virtual string AcctName { get; set; }
public abstract class acctCD : BqlString.Field<acctCD> { }
[PXDBString(128, InputMask = "", IsUnicode = true)]
[PXUIField(DisplayName = REMessages.DisplayNames.AcctCD, Visibility = PXUIVisibility.SelectorVisible)]
public virtual string AcctCD { get; set; }
}
** DAC Integration **
[PXDBInt]
[PXUIField(DisplayName = REMessages.DisplayNames.InvestorsName, Required = true)]
[InvestorSelector()]
[PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
public virtual int? ContactID { get; set; }
I really need your help and suggestions. Thank you so much.
Is ok to have 2 fields defined and one displayed.
Each one with his own selector, and PXUIField Description.
You set visibility for one of them base on the setup field at graph level (RowSelected event)
In case you need to merge them on persist (persist both fields in one bound field), you can simply use 2 unbound fields for collecting/displaying data.
on updating/persisting event, you can update the values from unbound fields to unique database field
on retrieve you can make an Data View - Delegate to populate the unbound fields base on configuration;
When you plan to move on multiple pages (graphs) you move the code from the graph to an PXEventSubscriberAttribute
You add the new attribute at the DAC level.
This way you have access on all Graph events that may need (persisting, selecting, updating, ...). All the code stays in one place.
For multiple DACs you still need to create the fields; add them the new attribute.

How to change the Display Name for one of the PXSelector fields

I need to change the Display Name to "Primary Vendor" for a BAccount.acctName field, which is the last field to display in the PXSelector that I have created.
I have tried creating an field Extension which does the trick, but this option also renames the field for another inquiry page, therefore I cannot use it.
The following is my code:
Selector
[PXNonInstantiatedExtension]
public class SO_SOLine_ExistingColumn :
PXCacheExtension<PX.Objects.SO.SOLine>
{
#region InventoryID
[PXMergeAttributes(Method =
MergeMethod.Append)]
[PXSelector(typeof(Search2<InventoryItem.inventoryCD,
LeftJoin<BAccount, On<BAccount.bAccountID,
Equal<InventoryItem.preferredVendorID>>>,
Where<InventoryItem.descr, IsNotNull>>),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr),
typeof(InventoryItem.postClassID),
typeof(InventoryItem.itemStatus),
typeof(InventoryItem.itemType),
typeof(InventoryItem.baseUnit),
typeof(InventoryItem.salesUnit),
typeof(InventoryItem.purchaseUnit),
typeof(InventoryItem.basePrice),
typeof(BAccount.acctName), ValidateValue = false) ]
public int? InventoryID { get; set; }
#endregion
}
Field Extension
public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount>
{
#region UsrCustomField
[PXDBString(250, IsUnicode = true, BqlField =
typeof(BAccountR.acctName))]
[PXUIField(DisplayName = "Primary Vendor")]
public virtual string AcctName { get; set; }
public abstract class acctName : IBqlField
{
}
#endregion
}
As you found out the cache extension modifications applies to all screens who use that DAC. There is another extension mechanism applied on a per graph basis called CacheAttached that is applied after the cache extension.
To use it first you need to identify the graph of the screen you want to customize and the DAC field you want to modify. You can use the inspect element feature for this. In this example the graph for Customers screen is 'CustomerMaint' and the DAC field is 'Customer.acctName':
Once you have that information you can create an extension for that graph and extend the DAC field inside it. DAC field extensions defined in the graph using the CacheAttached method will only apply to screens who uses that graph:
public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "Display Name For Customers Graph")]
public virtual void Customer_AcctName_CacheAttached(PXCache sender)
{
}
}
The prototype convention for CacheAttached extensions is:
void DAC_DACField_CacheAttached(PXCache sender) { }
You change DAC and DACField to the field you are targeting. Method definition (body) should remain empty. The attributes decorating the CacheAttached method will apply to the field you're customizing. With attribute PXMerge you can tweak how the CacheAttached extension is applied, it allows to merge the field new attributes of the extension with the base one or completely replace the base attributes.
For more details look at this blog post:
http://asiablog.acumatica.com/2017/01/append-and-replace-of-dacs-attributes.html
you can also try like below but this is limited to the specific graph.
public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
public override void Initialize()
{
PXUIFieldAttribute.SetDisplayName<Customer.acctName>(Base.BAccount.Cache, "Primary Vendor");
}
}

PXFormula not updating

I've created a new custom bound field UsrMatchCode for the BAccount DAC. My goal is to create a field which I can query from a web service call to identify "potential" duplicate customer records. My plan is to concatenate the following into a single 9-character calculated field:
First 5 Characters of Address.PostalCode
First 2 Characters of Address.AddressLine1
First 2 Characters of Contact.FullName
But before I can get this far, I'm stuck getting the value of the PXFormula to display when updating/saving existing records. Strangely, it does output a value for new records. See screenshot.
I've reduced the PXFormula to using constants only to rule out other fields causing the problem.
public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount>
{
private class index1 : Constant<int>
{
public index1() : base(0) { }
}
private class length5 : Constant<int>
{
public length5() : base(5) { }
}
private class testString : Constant<string>
{
public testString() : base("123456789") { }
}
#region UsrMatchCode
public abstract class usrMatchCode : IBqlField { }
[PXDBString(9)]
[PXUIField(DisplayName = "Match Code", Enabled = false)]
[PXFormula(typeof(Substring<testString, index1, length5>))]
public virtual string UsrMatchCode { get; set; }
#endregion
}
I feel like I'm missing something obvious, but I can't work it out.
I avoid using PXFormula and PXDBxxx types at the same time.
The PXDBxxx attribute tells the framework you want to persist the field value to DB and reload it's value from DB while PXFormula tells the framework the string value needs to be computed from the formula. The two approach appear incompatible because it's not clear cut whether the value will be coming from DB or from formula after the record has been persisted to DB. Other attributes like PXDefault are more suited for PXDBxxx types because it will only run at initialisation.
I would recommend either to use PXFormula with the unbound PXString type or to use PXDefault instead of PXFormula for initialisation of PXDBString.

Resources