Skip to main content
Solved

Can we make some web endpoints read-only? And can we do the same for individual fields?

  • October 4, 2022
  • 2 replies
  • 79 views

Forum|alt.badge.img+7

I’d like to be able to make one of the web endpoints read-only.  Is that possible without going through security/roles?

There are some other web endpoints that I would like to make specific fields read-only as well. Is there a way to do that?  I could make a non-persisted field that mirrors the value of the field I want to display and expose that in the endpoint. I’m wondering if I’ve overlooked something.

 

Best answer by Leonardo Justiniano

Hi @ddunn 

Certainly using Roles to restrict which entities the API user can write would work. Having specific fields read only requires customizing the screen to prevent setting a value. Something like:

 

protected void _(Events.RowUpdating<DAC> e)
{
// If you want to validate only the REST API call
if(Base.IsContractBasedAPI && e.Row.Field != e.NewRow.Field)
{
throw new PXException("ERROR: FIELD READ ONLY") ;
}
}

 

2 replies

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi @ddunn 

Certainly using Roles to restrict which entities the API user can write would work. Having specific fields read only requires customizing the screen to prevent setting a value. Something like:

 

protected void _(Events.RowUpdating<DAC> e)
{
// If you want to validate only the REST API call
if(Base.IsContractBasedAPI && e.Row.Field != e.NewRow.Field)
{
throw new PXException("ERROR: FIELD READ ONLY") ;
}
}

 


Forum|alt.badge.img+7
  • Author
  • Captain II
  • October 5, 2022

I thought that there might be a property that would indicate if the code was running via the Contract API or not.  Thank you!