Reputation: 1
The client has an Attribute added to the Contact(CR302000). Now they would like to see that attribute as column when viewing the contact on the "Business Account(CR303000)" screen under Contact Tab.
I created customisation and added the attribute (Region_Attribute) in Business Account (CR303000)>Tab:CurrentBaccount>Contacts by selecting it from "ADD DATA FIELD>ALL". I published the customisation but this field is not visible on the Contact Tab or the Column Configuration. Can you please help.
Thanks.
Upvotes: 0
Views: 126
Reputation: 7706
You can create a new custom field, write a FieldSelecting
event handler like below and add it to the grid instead of the one you added. This will find the Attribute value for the specific record and show it.
using PX.CS.Contracts.Interfaces;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Data.EP;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CR.MassProcess;
using PX.Objects.CR.Workflows;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.EP;
using PX.Objects.GDPR;
using PX.Objects;
using PX.SM;
using PX.TM;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System;
namespace PX.Objects.CR
{
public class ContactExt : PXCacheExtension<PX.Objects.CR.Contact>
{
#region UsrCustomAttributeRegion
[UsrRegionValue(typeof(PX.Objects.CR.Contact.contactID))]
public virtual string UsrCustomAttributeRegion { get; set; }
public abstract class usrCustomAttributeRegion : PX.Data.BQL.BqlString.Field<usrCustomAttributeRegion> { }
#endregion
}
[PXString(255,IsUnicode = true)]
[PXUIField(DisplayName = "Region", Enabled = false)]
public class UsrRegionValueAttribute : PXAggregateAttribute, IPXFieldSelectingSubscriber
{
protected Type ContactIDType;
public UsrRegionValueAttribute(Type contactID)
{
ContactIDType = contactID;
}
public void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
e.ReturnValue = null;
if (e.Row != null)
{
var contactID = (int)sender.GetValue(e.Row, ContactIDType.Name);
Contact contact = PXSelect<Contact, Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.SelectWindowed(sender.Graph, 0, 1, new object[] { contactID });
CSAnswers answer = PXSelect<CSAnswers, Where<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>,
And<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>>>>.SelectWindowed(sender.Graph, 0, 1, new object[] { "REGION",contact.NoteID });
if(answer!=null)
e.ReturnValue = answer.Value;
}
}
}
}
Upvotes: 0