Solved

Using PXSelect within PXSelect Gives Type Error

  • 8 August 2022
  • 4 replies
  • 267 views

Userlevel 4
Badge +1

Hello,

I’m currently trying to execute an action where when the button is pushed, it will look at the current employee selected on the service appointment, go to that employee (where the default workgroup id exists), and then once that record is found, I use the defaultworkgroupid to pass into a second pxselect to find all employees that share the same default workgroup. I then run the foreach loop to add them to the appointment.

However, I am getting an error (see below) where the type is not correct. I have a feeling that I need to run a join on my select but I’m not entirely sure how to go about it. 

    {
#region Views

public PXSelect<EPEmployee, Where<EPEmployee.bAccountID, Equal<Current<FSAppointmentEmployee.employeeID>>>> EmpLead;

#endregion

#region Actions

public PXAction<FSAppointmentEmployee> AddCrew;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Add Crew", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
protected void addCrew()
{
//EPEmployee lead = PXSelect<EPEmployee, Where <EPEmployee.bAccountID, Equal<Current<FSAppointmentEmployee.employeeID>>>>.Select(Base);

EPEmployee lead = EmpLead.Current as EPEmployee;

foreach (PXResult<EPEmployee> crew in PXSelect<EPEmployee, Where<EPEmployee.defaultWorkgroupID, Equal<lead.DefaultWorkgroupID>>>.Select(Base))
{
EPEmployee employee = crew;
FSAppointmentEmployee newCrew = new FSAppointmentEmployee();
newCrew.EmployeeID = employee.BAccountID;
Base.AppointmentServiceEmployees.Insert(newCrew);
}
}
}

 

icon

Best answer by Shawn Burt 9 August 2022, 00:09

View original

4 replies

Userlevel 5
Badge +1

lead is a variable, the query you are running you are trying to use it as a type.

you need to switch to a Required parameter and pass the Iead in that way.

 

something like this:

foreach (PXResult<EPEmployee> crew in PXSelect<EPEmployee, Where<EPEmployee.defaultWorkgroupID, Equal<Required<EPEmployee.defaultWorkgroupID>>>>.Select(Base,lead.DefaultWorkgroupID))

 

Userlevel 4
Badge +1

Thanks, @Shawn Burt- that got me past the visual validation and I was able to publish.

Now I’m getting an object reference issue on that line. Not sure if it’s because of the statement or the way I’m trying to use it.

 

Userlevel 5
Badge +1

you may want to use:
lead?.DefaultWorkgroupID in the select.

If lead is null then it would generate that error. I just kind of assumed that the lead variable would have a value

Userlevel 4
Badge +1

@Shawn Burt - Nevermind.. I did some refactoring on the other portions of the code and got it to work. You’re the best! For everyone’s reference.. working code below:

    public class AppointmentEntry_Extension : PXGraphExtension<PX.Objects.FS.AppointmentEntry>
{
#region Views

//public PXSelect<EPEmployee, Where<EPEmployee.bAccountID, Equal<Current<FSAppointmentEmployee.employeeID>>>> EmpLead;

#endregion

#region Actions

public PXAction<FSAppointmentEmployee> AddCrew;
[PXUIField(DisplayName = "Add Crew", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public virtual IEnumerable addCrew(PXAdapter adapter)
{
EPEmployee lead = PXSelect<EPEmployee, Where <EPEmployee.bAccountID, Equal<Current<FSAppointmentEmployee.employeeID>>>>.Select(Base);

//EPEmployee lead = EmpLead.Current as EPEmployee;

foreach (EPEmployee crew in PXSelect<EPEmployee, Where<EPEmployee.defaultWorkgroupID, Equal<Required<EPEmployee.defaultWorkgroupID>>>>.Select(Base, lead.DefaultWorkgroupID))
{
FSAppointmentEmployee addCrew = new FSAppointmentEmployee();
addCrew.EmployeeID = crew.BAccountID;
addCrew.AppointmentID = Base.AppointmentServiceEmployees.Current.AppointmentID;
addCrew.IsDriver = false;
Base.AppointmentServiceEmployees.Cache.Update(addCrew);
}

return adapter.Get();
}
}
#endregion

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved