Solved

How to get stored value of custom field instead of displayed value in web service endpoint

  • 26 October 2023
  • 6 replies
  • 82 views

Userlevel 2
Badge

I’ve added a new string field to InventoryItem:

        #region UsrMCVisibility
[PXDBString(1, IsFixed = true)]
[PXUIField(DisplayName = "Visiblility")]
[PXDefault(typeof(ItemVisibility.shopDefault), PersistingCheck = PXPersistingCheck.Nothing)]
[ItemVisibility]
public virtual string UsrMCVisibility { get; set; }
public abstract class usrMCVisibility : PX.Data.BQL.BqlString.Field<usrMCVisibility> { }
#endregion

ItemVisibility is a PXStringListAttribute:

    public class ItemVisibility : PXStringListAttribute
{
public const string ShopDefault = "X";
public const string Visible = "V";
public const string Featured = "F";
public const string Invisible = "I";

public class shopDefault : PX.Data.BQL.BqlString.Constant<shopDefault>
{
public shopDefault() : base(ShopDefault) {; }
}
public class visible : PX.Data.BQL.BqlString.Constant<visible>
{
public visible() : base(Visible) {; }
}
public class featured : PX.Data.BQL.BqlString.Constant<featured>
{
public featured() : base(Featured) {; }
}
public class invisible : PX.Data.BQL.BqlString.Constant<invisible>
{
public invisible() : base(Invisible) {; }
}

public ItemVisibility()
: base(new string[4] {
ShopDefault,
Visible,
Featured,
Invisible
}, new string[4] {
Messages.ItemVisibility_ShopDefault,
Messages.ItemVisibility_Visible,
Messages.ItemVisibility_Featured,
Messages.ItemVisibility_Invisible
})
{
}
}

When i now extend an web service endpoint with this field i get the labels on querying the api but i want to get the values stored in the database. How to achieve this?

icon

Best answer by RohitRattan88 26 October 2023, 19:49

View original

6 replies

Userlevel 7
Badge +4

@priekenberg40  are you querying on InventoryItem entity? or oData v4, v3?

Userlevel 2
Badge

@RohitRattan88  RestAPI, InventoryItem entity.

Userlevel 7
Badge +4

Hey @priekenberg40,

I am not sure if that is possible to fetch the value.

But there is an alternate you could try, in the RowSelected event you can check if the request is from API and set the value there. In your case, you can add condition and send the equivalent values for the label that is being set for that record.

Following is an sample implementation you could try,

    public class InventoryItemMaint_Extension : PXGraphExtension<PX.Objects.IN.InventoryItemMaint>
{
#region Event Handlers

protected void InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected baseMethod)
{
baseMethod?.Invoke(cache, e);
var row = (InventoryItem)e.Row;
if (Base.IsContractBasedAPI == true)
{
//Add condition and reassign values of the lables
InventoryItemExt rowExt = cache.GetExtension<InventoryItemExt>(row);
rowExt.UsrMCVisibility = "For API";
}
}
#endregion
}

Good Luck,

Userlevel 7
Badge +4

@priekenberg40 I couldnt find much relevant documentation but found some Attribute related information @ TOOLS Retrieve Records with Attributes

  • ValueDescription: The external value of the attribute. The field is read-only. The external value is based on the control type as follows:
    • For text boxes and date edit boxes, the external value is the same as the internal value.
    • For check boxes, the external value can be either True or False.
    • For combo boxes, the label is used as the external value.
    • For multiselect combo boxes, labels separated by commas and spaces after commas (namely, Label1, Label2, Label3) compose the external value.

As a workaround though, you could try adding an Unbound field to store your UsrMCVisibility value and pull it in the API:

	#region UsrMCVisibilityVal
[PXString]
[PXUIField(DisplayName="Visiblility Value", Enabled = false)]
[PXDBCalced(typeof(InventoryItem.usrMCVisibility), typeof(string))]
public virtual string? UsrMCVisibilityVal { get; set; }
public abstract class usrMCVisibilityVal: PX.Data.BQL.BqlInt.Field<usrMCVisibilityVal> { }
#endregion

Hopefully it helps.

Userlevel 2
Badge

@RohitRattan88 i also did the workaround with an unbound field without ListAttribute. I filled the value in RowSelecting. This is even more elegant using PXDBCalced. Thanks.

Btw.: I’ve seen other API extensions which use a suffix in the field mapping like “$value” or “_description”. None of them helped here.
 

                <Mapping field="Attributes">
<Mapping field="AttributeDescription">
<To object="Answers" field="AttributeID_description" />
</Mapping>
<Mapping field="AttributeID">
<To object="Answers" field="AttributeID$value" />
</Mapping>
<Mapping field="Value">
<To object="Answers" field="Value$value" />
</Mapping>
<Mapping field="ValueDescription">
<To object="Answers" field="Value" />
</Mapping>
</Mapping>

 

Userlevel 7
Badge +4

@RohitRattan88i also did the workaround with an unbound field without ListAttribute. I filled the value in RowSelecting. This is even more elegant using PXDBCalced. Thanks.
 

@priekenberg40 Please note that some(probably most) of these event are only triggered via UI hence you may not see the values populated in API. PXDBCalced is the suggested way to approach such issues.

Good luck with your integration.

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