Solved

Reg : PXSelector with same Code

  • 23 June 2023
  • 5 replies
  • 130 views

Hi Team,

PXSelector with same code name not able to select the correct code. If it is having two same code means it will be when we select the second one it will will automatically point to the first one.

 

Please find the selector and image.

  #region Location
[PXDBString(50)]
[PXUIField(DisplayName = "Project Location")]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXSelector(
typeof(Search<ProjectLocation.locationID>),
DescriptionField = typeof(ProjectLocation.description), SubstituteKey = typeof(ProjectLocation.locationID))]
public virtual string Location { get; set; }
public abstract class location : PX.Data.BQL.BqlString.Field<location> { }
#endregion

 

Regards,

Sakthi

icon

Best answer by davidnavasardyan09 28 June 2023, 05:30

View original

5 replies

Hi Team,

 

Any help on this?

 

Regards,

Sakthi

Userlevel 7
Badge +17

Hi @sakthi61 Assuming that ProjectLocation is a custom DAC.

If yes, for that custom DAC, make sure to not allow duplicate ID’s by providing the Is Key= “true” for both the Location ID and Description at DAC.

This way you can avoid duplicate values at the Project Location selector.

 

Hi @sakthi61 Assuming that ProjectLocation is a custom DAC.

If yes, for that custom DAC, make sure to not allow duplicate ID’s by providing the Is Key= “true” for both the Location ID and Description at DAC.

This way you can avoid duplicate values at the Project Location selector.

 

I still need duplicate code. Id is already Primary Key. I need duplicate Code but selection not selecting the actual value. If select the second item but it is always selecting the first one.

 

Regards,

Sakthi 

Userlevel 7
Badge +17

Hi @sakthi61  As you are searching for the Location ID in your Selector, it might be taking the first record.

Something is wrong with KEYS for this DAC (Project Location) and you might need to change this and work on it.

 

Userlevel 5
Badge +1

@sakthi61 

he problem you are encountering is related to the SubstituteKey property in the PXSelector attribute. The SubstituteKey property is used when you want to display a user-friendly field to the end user but store a different value in the database.

In your case, SubstituteKey = typeof(ProjectLocation.locationID) causes the selector to display locationID, and when a record is selected, the locationID value is stored in the database.

When there are duplicate values for locationID, Acumatica gets confused and always picks the first occurrence because it's not designed to handle duplicate keys. The locationID field should be unique.

One solution would be to modify your data to ensure that locationID values are unique. However, if you cannot ensure uniqueness and you want to show a user-friendly name (like description), you could consider creating a concatenated field in your DAC, something like locationDescrAndID, which could be a combination of locationID and description, or any other field that ensures uniqueness. Then, you could use that field as the SubstituteKey.

Here's an example:

#region Location
[PXDBString(50)]
[PXUIField(DisplayName = "Project Location")]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXSelector(
typeof(Search<ProjectLocation.locationDescrAndID>),
DescriptionField = typeof(ProjectLocation.description),
SubstituteKey = typeof(ProjectLocation.locationDescrAndID))]
public virtual string Location { get; set; }
public abstract class location : PX.Data.BQL.BqlString.Field<location> { }
#endregion

In ProjectLocation DAC:

public abstract class locationDescrAndID : PX.Data.BQL.BqlString.Field<locationDescrAndID> { }

[PXDBCalced(typeof(Add<projectLocation.locationID, projectLocation.description>), typeof(string))]
[PXUIField(DisplayName = "Location ID and Description", Enabled = false)]
public virtual string LocationDescrAndID { get; set; }

This is a calculated field which would concatenate the locationID and description fields. Note: You might need to adjust the code based on your requirements and ensure the uniqueness of LocationDescrAndID.

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