Would like to create a Customization to populate a Customers Primary Contact in the contact field of the settings tab on an appointment by default. Please help!
Answer
Primary Contact as Default on Appointments
Best answer by Abhishek Niikam
Hi
protected void FSAppointment_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
FSAppointment appointment = e.Row as FSAppointment;
if (appointment == null || appointment.CustomerID == null)
return;
// Retrieve the Customer's Primary Contact
BAccount baccount = PXSelect<BAccount,
Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>
.Select(Base, appointment.CustomerID);
if (baccount?.PrimaryContactID != null)
{
// Get the related Service Order record
FSServiceOrder serviceOrder = PXSelect<FSServiceOrder,
Where<FSServiceOrder.srvOrdType, Equal<Required<FSServiceOrder.srvOrdType>>,
And<FSServiceOrder.refNbr, Equal<Required<FSServiceOrder.refNbr>>>>>
.Select(Base, appointment.SrvOrdType, appointment.RefNbr);
if (serviceOrder != null)
{
serviceOrder.ContactID = baccount.PrimaryContactID;
Base.ServiceOrderRelated.Update(serviceOrder);
}
}
}
Hope, it helps!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.