Skip to main content

I have added a custom field on the header of the Project Transaction screen, but I need this to be editable when the transaction is released.

This screen has no workflow, so wondering if anyone can assist with how to do this please.

Its all enabled, and I can update it on screen, but when I press save, it loses the data / does not actually save it to the PMRegister table.

Hi @lbarker 

 

You could use something like this for the visibility:

protected virtual void _(Events.RowSelected<PMRegister> e, PXRowSelected b)

b?.Invoke(e.Cache, e.Args);

if(row.Status == “R”)

{

PXUIFieldAttribute.SetEnabled<PMRegister.UsrCustomField>(e.Cache, e.Row, false);

}

For persisting, is there a database script for this field?

 

Aleks


Hi @lbarker,

 

Could you please try below code snippet?  Please replace usrTest field with your custom field.

 protected void PMRegister_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (PMRegister)e.Row;
if (row == null) return;

// Allow the custom field to be editable even after release
PMRegisterExt rowExt = cache.GetExtension<PMRegisterExt>(row);

if (row.Released == true)
{
cache.AllowUpdate = true; // Allow updates on released records
PXUIFieldAttribute.SetEnabled<PMRegisterExt.usrTest>(cache, row, true);
}
}

Hope, it helps!

 


Thanks for the help but sadly same issue. 

Its enabled, and press Save action works on screen, but the data does not actually save to the custom field if the record is flagged as released.

 


Hi @lbarker ,

Could you please confirm Is the custom field is DB field? 

Please provide your custom field code, how you have declared at DAC level?


Yes I added it to the DB under Database Scripts and have not changed the attributes using Data Class.

Can use it if the transaction is not released so its saving only in that instance


Hi @lbarker 

 

Have you tried something like this:

protected virtual void _(Events.RowSelected<PMRegister> e, PXRowSelected b)

b?.Invoke(e.Cache, e.Args);

PMRegisterExt rowExt = row.GetExtension<PMRegisterExt>;

if(row.Status == “R”)

{

//Sets the field as enabled

PXUIFieldAttribute.SetEnabled<PMRegisterExt.UsrCustomField>(e.Cache, e.Row, true);

//Sets the field as visible

PXUIFieldAttribute.SetVisible<PMRegisterExt.UsrCustomField>(e.Cache, e.Row, true);

}

You will have to do this in a Graph extension for the graph responsible for the screen you are using.

 

For the field not saving, you can try directly removing it completely, publishing the customisation project, then adding it from the screen editor, it creates a DAC extension and a DB script to ensure that the field persists, publishing the project to make the field available, then adding the field to the screen where you want it, then publish again with the graph extension. 

 

To find the graph, press ctrl + alt on a field and this will come up:

you want to create a code file, type of graph extension, and select the graph named in the ‘Business Logic’ field.

Aleks


It would be helpful to see your field definition.


Yeh the field is fine and is in the database,  as can edit it no problem and save it from add record point to release point.

For released records we want to be able to edit it and save it.

Its only when the record is flagged as released, we can edit it, but after pressing save its actually not saved to the data.


Hello @lbarker ,

 

It is likely that the Cache is not updated with the value to save to the DB after release. Assuming there is a Field Updated event on the custom field, try the below line of code that forces the Cache to consider the modified records to persist. Make sure the CommitChanges property of the custom field is set to TRUE as well.

var doc = Cachesetypeof(TPrimary)].Current;
Cachesetypeof(TPrimary)].MarkUpdated(doc);

 


Reply