I created one new extension field in Contacts screen (location id --- int) and in customer location screen when I click on the "+" button it should redirect to contacts screen and the header session "Customer and Location ID" should default but Location ID is not defaulting.
Here is the img example:
And this is the code what I wrote:
public PXDBAction<Location> addContact;
[PXUIField(DisplayName = Messages.AddContact)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
public virtual void AddContact()
{
var row = Base.Location.Current;
if (row == null || row.BAccountID == null) return;
ContactExt extension = PXCache<Contact>.GetExtension<ContactExt>(Base.Contact.Current); //Base.Contact.Current
ContactMaint graph = PXGraph.CreateInstance<ContactMaint>();
graph.Clear();
Location get = Base.Location.Current;
Contact retbatch = graph.Contact.Insert(new Contact());
retbatch.BAccountID = get.BAccountID;
extension.UsrLocationCD = get.LocationID;
if (!Base.IsContractBasedAPI)
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
graph.Save.Press();
}
Newly created extension field logic:
public class ContactExt : PXCacheExtension<PX.Objects.CR.Contact> /*, IBqlTable*/
{
#region UsrLocationCD
[PXDBInt()]
[PXUIField(DisplayName = "Location ID")]
[PXSelector(
typeof(Search<Location.locationID, Where<Location.bAccountID,
Equal<Current<Contact.bAccountID>>>>),
SubstituteKey = typeof(Location.locationCD), ValidateValue = false)]
public virtual int? UsrLocationCD { get; set; }
public abstract class usrLocationCD : PX.Data.BQL.BqlInt.Field<usrLocationCD> { }
#endregion
}
This is the Breakpoint img:
And like this similar functionality should happens in Opportunities screen
Img example:
And this is the similar code (Opportunities screen):
public PXDBAction<Location> addOpportunity;
[PXUIField(DisplayName = Messages.AddNewOpportunity)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.AddNew)]
public virtual void AddOpportunity()
{
var row = CurrentBAccount.Current;
if (row == null || row.BAccountID == null) return;
OpportunityMaint graph = PXGraph.CreateInstance<OpportunityMaint>();
graph.Clear();
Location get = Base.Location.Current;
CROpportunity retbatch = graph.Opportunity.Insert(new CROpportunity());
retbatch.BAccountID = get.BAccountID;
retbatch.LocationID = get.LocationID;
if (!Base.IsContractBasedAPI)
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
graph.Save.Press();
}
this is the Breakpoint img:
functionality is working in Opportunities screen
Where is the mistake in the "Contacts screen" logic and how to overcome this issue?
I'm new to this acumatica.