Reputation: 361
I am creating a customer in code. Straight after I create the customer I perform a PXSelect to retrieve the customer by the acctCd. But it returns null everytime. Even though I have checked to the database and verified it exists?
I'm guessing this is something to do with the cache how do I refresh this.
Here is my PXSelect
PXSelect<PX.Objects.AR.Customer, Where<PX.Objects.AR.Customer.acctCD, Equal<Required<PX.Objects.AR.Customer.acctCD>>>>.Select(this, id);
Here is my code that add customer
private PX.Objects.AR.Customer UpdateContact(ContactRead rexContact, PX.Objects.AR.Customer m, string customerClassID, bool insert = true)
{
PX.Objects.CR.Contact defContact = null;
PX.Objects.AR.CustomerMaintInherit graph = PXGraph.CreateInstance<PX.Objects.AR.CustomerMaintInherit>();
graph.Clear(PXClearOption.ClearAll);
//Add Customer and BAccount Records
graph.BAccount.Current = m;
m.AcctCD = "V" + rexContact._id;
m.AcctName = rexContact.system_search_key;
m.Type = "CU";
if (insert) {
m = graph.BAccount.Insert(m);
defContact = graph.DefContact.Current;
}
else {
defContact = PXSelect<PX.Objects.CR.Contact, Where<PX.Objects.CR.Contact.contactID, Equal<Required<PX.Objects.CR.Contact.contactID>>>>.Select(this, m.DefContactID);
graph.DefContact.Current = defContact;
}
//Update Default Contact Record
defContact.ContactType = "AP";
defContact.FullName = rexContact.system_search_key;
if (rexContact._related.contact_emails != null)
{
if (rexContact._related.contact_emails.Length > 0)
{
defContact.EMail = (from e in rexContact._related.contact_emails where e.email_primary == true select e.email_address).FirstOrDefault();
}
}
if (rexContact._related.contact_phones != null)
{
if (rexContact._related.contact_phones.Length > 0)
{
defContact.Phone1 = (from e in rexContact._related.contact_phones where e.phone_primary == true select e.phone_number).FirstOrDefault();
}
}
defContact = graph.DefContact.Update(defContact);
//Change customer class to vendor
m.CustomerClassID = customerClassID;
m = (PX.Objects.AR.Customer)graph.BAccount.Update(m);
graph.Actions.PressSave();
return m;
}
Upvotes: 0
Views: 812
Reputation: 5151
Consider usage PXSelectReadonly. It will try to retrieve value directly from db without usage of cache. Another option is to create instance of graph, with needed view, and through that graph ask db with PXSelect
Upvotes: 2