Skip to main content
Solved

i need to fetch Attention, Email, Phone1 and Phone2 from Contact but this query not working properly

  • 4 July 2024
  • 7 replies
  • 58 views

Why Sometimes this query return null and some time it will return result? 

   

 var result = PXSelectReadonly2<PX.Objects.GL.Branch,
        InnerJoin<PX.Objects.GL.DAC.Organization, On<PX.Objects.GL.DAC.Organization.organizationID, Equal<PX.Objects.GL.Branch.organizationID>>,
        InnerJoin<PX.Objects.CR.BAccount, On<PX.Objects.CR.BAccount.bAccountID, Equal<PX.Objects.GL.DAC.Organization.bAccountID>>,
        InnerJoin<PX.Objects.CR.Contact, On<PX.Objects.CR.Contact.contactID, Equal<PX.Objects.CR.BAccount.defContactID>>>>>,
        Where<PX.Objects.GL.Branch.branchID, Equal<Required<PX.Objects.GL.Branch.branchID>>>>.Select(graph, graph.Accessinfo.BranchID);

7 replies

Userlevel 7
Badge +19

@hyadav08  Try the below code and verify.

 

   PX.Objects.CR.BAccount objBAccount = PXSelectJoin<PX.Objects.CR.BAccount, 
InnerJoin<Organization, On<Organization.bAccountID, Equal<PX.Objects.CR.BAccount.bAccountID>>,
InnerJoin<PX.Objects.GL.Branch,On<PX.Objects.GL.Branch.organizationID,Equal<Organization.organizationID>>>>,
Where<PX.Objects.GL.Branch.branchID,Equal<Required<PX.Objects.GL.Branch.branchID>>>>.
Select(customerMaint, customerMaint.Accessinfo?.BranchID);

if (objBAccount != null)
{
OrganizationMaint OMaint = PXGraph.CreateInstance<OrganizationMaint>();

OrganizationBAccount OBAccount = PXSelect<OrganizationBAccount, Where<OrganizationBAccount.bAccountID,
Equal<Required<OrganizationBAccount.bAccountID>>>>.Select(OMaint, objBAccount?.BAccountID);
if (OBAccount != null)
{
OMaint.BAccount.Current = OBAccount;

PX.Objects.CR.Address MainAddress = OMaint.GetExtension<OrganizationMaint.DefContactAddressExt>().DefAddress.Select()[0];
PX.Objects.CR.Contact MainContact = OMaint.GetExtension<OrganizationMaint.DefContactAddressExt>().DefContact.Select()[0];

// Get The Address Details from MainAddress object
//Get the Contact Details from MainContact object


}
}

 

@Naveen Boga 
I have Try the above code and check objBAccount is null.
Why this is given null to me and also suggest the other solution to extract  Attention, Email, Phone1 and Phone2 from Contact ?

Userlevel 7
Badge +19

@hyadav08 I think this is an issue with your graph i.e. CustomerMaint.

To confirm this, Can you please replace the new PXGraph() ( This is just for your testing and I recommend to use the PXGraph())

 

Once it is confirmed then pass the right graph from your code and verify 

@Naveen Boga  We haven’t use  new PXGraph()

Userlevel 7
Badge +19

Sure, Have you tried with right graph and it is working fine?

I have found solution the below code given me the correct contact detail
 

List<Contact> contacts = PX.Objects.CS.OrganizationMaint.GetDefaultContactForCurrentOrganization(graph).ToList(); 
            foreach(Contact cont in contacts) { 

                UserTranInfo.ContactName = cont.Attention;
                UserTranInfo.ContactEmail = cont.EMail;
                UserTranInfo.ContactPhone1 = cont.Phone1;
                UserTranInfo.ContactPhone2 = cont.Phone2;
            }

Userlevel 7
Badge

Thank you for sharing your solution with the community @hyadav08!

Reply