MikeNIke
MikeNIke

Reputation: 233

How to Enable Fields when used from API

How can I set fields to be updateable in the API but, read-only on the screen?

I have a view with a custom table defined in a Graph extension. I am using the (ViewName).AllowUpdate = false; on the RowSelected event of the primary DAC. This works fine to make all of the fields in the view disabled on the screen but, I can't update the fields in the API. Is there some way to detect that the graph is being used in the API versus the screen?

TIA!

Upvotes: 0

Views: 177

Answers (2)

Raj
Raj

Reputation: 61

I had a similar requirement to allow edit on a custom field in Shipment graph only through API and not through UI.

You could use the Graph.IsContractBasedAPI method that returns true if the request came through contract based API as shown below:

PXUIFieldAttribute.SetEnabled<SOShipLineExt.usrBOLQty>(cache, e.Row, Base.IsContractBasedAPI);

Upvotes: 0

Jean Claude Abela
Jean Claude Abela

Reputation: 907

What you can do is in the row selected event instead of affecting the restriction at cache level, which as you said affects the API as well, you can use the PXUIFieldAttribute to achieve the same scenario without affecting the API.

Ex: PXUIFieldAttribute.SetReadOnly([ViewName].Cache, null, [Condition or just set as true])

This will set all the fields in that view as readonly, without having to repeat the line for all the fields currently in the screen.

Upvotes: 1

Related Questions