Reputation: 135
suppose on screen SO301000 I have a PXSelector:
namespace PX.Objects.SO
{
public class SOOrderExt : PXCacheExtension<PX.Objects.SO.SOOrder>
{
#region UsrOrderByContact
[PXDBInt]
[PXDefault(typeof(Contact),PersistingCheck=PXPersistingCheck.Nothing)]
[PXUIField(DisplayName="Ordered By")]
[PXSelector(
typeof(Search<Contact.contactID,
Where<Contact.bAccountID, Equal<Current<SOOrder.customerID>>,
And<Contact.contactType, Equal<ContactTypesAttribute.person>>>>),
new Type[]
{
typeof(Contact.lastName),
typeof(Contact.firstName),
typeof(Contact.phone1)
},
SubstituteKey = typeof(Contact.displayName)
)]
public virtual int? UsrOrderByContact { get; set; }
public abstract class usrOrderByContact : IBqlField { }
#endregion
}
}
And ASPX:
<px:PXSelector runat="server" ID="CstPXSelector15" DataField="UsrOrderByContact" AllowAddNew="True" AllowEdit="True" AutoAdjustColumns="True" />
This shows list of Contacts based on current Customer in Sales Order.
I want to add a new Contact, so I click the Pencil icon next to the selector, and I get a new window at screen CR302000.
How would I pass the value of the current SOOrder.CustomerID to the Contact.BAccountID field on screen CR302000?
Upvotes: 0
Views: 340
Reputation: 8288
The AllowEdit
feature (pencil) is a configuration option and doesn't involve programming. Because of that you can't make it do something that isn't already an out-of-box behavior.
So you'll have to drop AllowEdit
and replace it with an ordinary action button. You can style the button to show only the pencil icon. In the event handler you can populate the fields of the graph before redirecting the user:
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.RecordEdit]
public virtual IEnumerable EditContact(PXAdapter adapter)
{
bool createNewContact = [... false to open existing, true to create a new one...];
ContactMaint graph = PXGraph.CreateInstance<ContactMaint>();
if (createNewContact)
{
// Create new contact and initialize fields before redirecting
var newContact = (Contact)graph.Contact.Cache.CreateInstance();
newContact.BAccountID = [... SOOrder.CustomerID...];
graph.Contact.Current = newContact;
}
else
{
// If already selected, you want to redirect to the
// existing contact instead of creating a new one
graph.Contact.Current = graph.Contact.Search<Contact.contactID>([... current.ContactID ...]);
}
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
return adapter.Get();
}
Upvotes: 1