Enable/Disable Single Field Programatically in SOLine - acumatica

I know that using
PXUIFieldAttribute.SetEnabled(sender, e.Row, false);
disables an entire row for SOLine. Is there anything I can use to specifically target which elements within the SOLine that I can disable instead of disabling the entire line?

Use this call...
PXUIFieldAttribute.SetEnabled<SOLine.myField>(
sender, e.row, false);
Replace SOLine.myField with your field you want to enabled/disable and set your true/false to enable/disable

Related

Changing visibility of shared Contact field on Customers screen in 2020R2?

I need to set Visible state of the Primary Contact->Email field on the Customers screen (General tab) to hidden.
In 2020R2 it's not clear to me how these Views are implemented. They have the same names, but seem to work differently than previous versions of Acumatica. In the version I'm upgrading from, 2019R1, the Primary Contact section doesn't exist.
I've created this event handler to hide the email field. But, it hides ALL the email fields: Both instances on the General tab, and also on the Billing and Shipping tabs. I only want to hide the field in the Primary Contact grouping.
protected virtual void _(Events.RowSelected<Contact> e)
{
PXUIFieldAttribute.SetVisible<Contact.eMail>(e.Cache, e.Row, false);
}
Is there a way to target just the Primary Contact email field with an event handler? When that field is inspected, the view name is: PrimaryContactCurrent. This view doesn't seem to exist in CodeRepository\CustomerMaint.cs, so I'm not sure how to target it with an event handler.
In 20R2 the logic for Contacts managements is located in separate graph extension CRPrimaryContactGraphExt and the PrimaryContactCurrent is defined there.
However, I don't think that's what you need. You are on the right track with the RowSelected event. You just need to add a condition to hide only needed field.
protected virtual void _(Events.RowSelected<Contact> e)
{
if(e.Row?.ContactID==Base.BAccount.Current?.PrimaryContactID)
PXUIFieldAttribute.SetVisible<Contact.eMail>(e.Cache, e.Row, false);
}

Acumatica Side Panel linked to detail item

I'm using Acumatica 2020R1 and I'm adding side panels. Is there anyway, for example on the PO form (PO301000), that I could link a side panel to update when clicking on the Document Details?
​
I actually discovered a way to do this on Acumatica 2020R1. Here's how I did it:
Edit: I did this for the SOOrderEntry screen, creating a side panel that looks at the SOOrder but uses parameters from the SOLine. This method will work for any two tables with a master-detail relationship by replacing SOOrder & SOLine accordingly.
Part A:
Create virtual fields on the SOOrder DAC that correlate to the SOLine Parameters you need
Update these as lines are selecting/updated using event handlers
pass these fields as the params to your side panel actions as you normally would
While It seems like this alone would work, the side panel actually doesn’t refresh when a new SOLine is selected. We’re going to have to get creative to resolve this issue.
Part B:
Create an additional virtual field on the SOOrder DAC to keep track of which side panel was last opened (I will explain how to track this later). I use a string field to do so. This is especially important if you have more than one side panel on your screen.
Next you want to define a standard graph action that will update this field. Make it Visible = false, since you don’t actually want this button to show. We will call if from behind the scenes later. This is the method I use:
public PXAction<SOOrder> SidePanelCallback;
[PXButton]
[PXUIField(DisplayName = "SidePanelCallback", Visible = false)]
public virtual IEnumerable sidePanelCallback(PXAdapter adapter)
{
SOOrder doc = Base.Document.Current;
if (doc == null) return adapter.Get();
var docExt = doc.GetExtension<SOOrderExt>();
docExt.UsrSidePanelDetailParamsRefresh = adapter.CommandArguments;
return adapter.Get();
}
*Note: docExt.UsrSidePanelDetailParamRefresh is the variable I for the previous step
Now you need a way to trigger your code when your side panel actions are called. To do this we’ll use the following JavaScript
function commandResult(ds, context) {
var ds = px_alls['ds'];
switch (context.command)
{
case ('JustAction'):
ds.executeCallback('GraphAction', 'parameter value');
break;
}
}
You want to replace JustAction with the internal name of your side panel action. it should look like this: NavigateToLayer$DB000028
where DB000028 is the target ScreenID for your sidepanel. If you want to make sure your actions follow the same naming convention, you can check it by adding breakpoints and checking with the debugger.
You should replace GraphAction with the name of the graph action you created in the previous step. In our case SidePanelCallback
Then finally for the parameter value pass whatever you’d like to use to identify the opened side panel. This will be stored in UsrSidePanelDetailParamRefresh, or your equivalent.
You can create a case statement for each side panel you want this functionality for, so you only have to do all this once per graph!
Then finally, attach your script to the client event ‘commandPerformed’ on your data source.
Next we will define another graph action to do the actual refresh of the side panel. Mine looks like this:
public PXAction<SOOrder> SidePanelRefresh;
[PXButton]
[PXUIField(DisplayName = "SidePanelRefresh", Visible = false)]
public virtual IEnumerable sidePanelRefresh(PXAdapter adapter)
{
SOOrder doc = Base.Document.Current;
if (doc == null) return adapter.Get();
var docExt = doc.GetExtension<SOOrderExt>();
Dictionary<string, string> parameters = new Dictionary<string, string>();
string[] args = adapter.CommandArguments.Split('*');
switch (docExt.UsrSidePanelDetailParamsRefresh)
{
case ("Component Inventory"):
parameters.Add("Kit", args[0]);
parameters.Add("SiteID", args[1]);
throw new PXRedirectToGIRequiredException("Component Inventory", parameters) { Mode = PXBaseRedirectException.WindowMode.Layer };
}
return adapter.Get();
}
Note that for my use case the parameters I am passing cannot contain the character ‘*’, so I use it as a delimiter
And again, you can define as many case statements as you need for each of your dynamic side panels.
And now finally we need javascript again to call this action. Using event handlers are too slow for this type of refresh, they will always pass the old SOLine parameters. If you know a way to avoid javascript here, I’d love to hear it, as doing callbacks like this does have a heavy overhead. Because of this, be careful where you attach this script to, I actually attach it to the grid’s RowSelectorClick client event rather than AfterRowChange for this reason, and train my users to select rows in this way (by clicking the arrow to the left of each row) so we don’t impact the rest of the company for the minority that use this feature. I’d recommend this if you're working on a high traffic screen such as SO301000.
Anyway, here’s the javascript:
function Side_Panel_Refresh() {
px_alls["ds"].executeCallback("SidePanelRefresh", this.func.caller.arguments[2].row.getCell("InventoryID").getValue() + "*" + this.func.caller.arguments[2].row.getCell("SiteID").getValue());
}
SidePanelRefresh: Name of our graph action from the previous step.
InventoryID & SiteID are my parameters.
And again, using ‘*’ as a delimiter.
 
Anyway, I hope this helps anyone looking to make dynamic side panels. If anyone has improvements on this method I’d love to hear constructive feedback.
Happy development!
​
It is a new feature. Side panel were restricted to generic inquiry. In version 2020 you still need a generic inquiry to configure the side panel but they can be viewed in data entry forms too.
The feature is implemented with wizards so it's pretty limited in what it can do. Currently you are limited to the choices available in navigation parameter. It seems like it's not possible to add details entity there. Maybe there's a way but I'm not aware of it.
Check documentation reference link for User Interface: Side Panels for Data Entry Forms (content copied below):
https://help-2020r1.acumatica.com/Help?ScreenId=ShowWiki&pageid=a11aa71b-5f18-4c8f-9c69-350f2c7a89f4
Adding a Side Panel to the Data Entry Form
A customizer can add multiple side panel navigation paths to a data entry form.
To add a side panel, the customizer navigates to the Customization Projects (SM204505) form and creates a new project.
In the Customization Project Editor, the customizer selects the screen for which the side panel is planned to be added.
On the Screens > Form ID > Actions, the customizer adds an action of the Navigation:
Side panel type (1), specifies general settings (2), adds destination screen (3), and specifies parameters (4), if needed (for instance, in the screenshot below, Business Account was selected as a parameter so that the side panel displayed the cases of the specific customer selected on the data entry form).
Example of a side panel on the Customers form
To apply the changes, the customizer must publish the created customization project.

How to make Acumatica custom action update the current record

I'm trying to make a custom action update a custom field on the current record. Eventually I need to work through all the deatils to collect some data, but for now I just need to click the button and have it update the current record. More or less, I think I fail to understand how to get the data that would be in a row level event like this protected void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
public PXAction<PX.Objects.SO.SOOrder> LookupShipping;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Lookup Shipping Rates")]
protected void lookupShipping()
{
SOOrder TheRow = Base.Document.Current;
}
Thanks in advance.
If you are trying to update custom fields...
First, you will want to connect to the DAC Extension via:
SOOrderExt sOOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(TheRow);
Then you need to update the field value. Assuming you are in a Graph Extension, you will need to utilize "Base" to access the cache.
Base.Caches[typeof(SOOrder)].SetValueExt<SOOrderExt.usrCustomField>(TheRow, InsertValueHere);
Once you update all field values, you need to actually update the cache itself.
Base.Caches[typeof(SOOrder)].Update(sOOrderExt);
And don't forget to save the record, assuming this button should be a one-stop shop.
Save.Press();
If you are trying to simply update the values in the existing view, you can do it very easily.
TheRow.FieldName = InsertValueHere;
Document.Current.Update(TheRow);
Save.Press();
You can see some good alternatives to updating values in HB_Acumatica's answer to where I asked something similar...
What is the proper way to update values of DAC's retrieved via PXResultset?

RowSelecting does not execute

I use the RowSelecting event, in order to perform a BQL query. I choose this event, since adding a BQL in RowSelected event is not advisable. My purpose is to assign a non-DB bound field (a boolean), which is used to enable/disable a field. During RowSelected event, the value is read, and a particular field is enabled/disabled, based on that value.
While using the debugger, I notice RowSelecting event does not fire when the form is first opened. Cancel button causes event to fire. Then I notice the api documentation...RowSelected & FieldSelecting events happen during sequence of events - display of record. RowSelecting is not mentioned.
My goal is to disable a field based on some BQL. What is the best way to perform the BQL and disable the field? Should I use RowSelected? Documentation says to avoid it. In my case, I refer to SO invoice entry form...specifically SOInvoice DAC.
You can extend the DAC in the Graph to add a PXUIEnabled Attribute to do this.
I updated my example to include a non-databound field that controls enabling and disabling another field.
In the SOInvoiceExt DAC Extension I have...
public class SOInvoiceExt : PXCacheExtension<PX.Objects.SO.SOInvoice>
{
#region UsrExtRefNbrDisabled
[PXBool]
[PXUIField(DisplayName = "ExtRefNbr Disabled?")]
public virtual bool? UsrExtRefNbrDisabled { get; set; }
public abstract class usrExtRefNbrDisabled : PX.Data.BQL.BqlBool.Field<usrExtRefNbrDisabled> { }
#endregion
}
Then I added the new custom field to the screen. Ensure that you set CommitChanges to True.
Then in the Graph Extension, I merged the PXUIEnabled attribute with the CachedAttached event
[PXUIEnabled(typeof(Where<SOInvoiceExt.usrExtRefNbrDisabled, NotEqual<True>>))]
[PXMergeAttributes(Method = MergeMethod.Merge)]
protected virtual void SOInvoice_ExtRefNbr_CacheAttached(PXCache cache)
{ }
I was able to check/uncheck the box and it enabled/disabled the field.
Here is an old blog post on the subject: https://asiablog.acumatica.com/2016/11/pxuienabled-and-pxuirequired-attributes.html
Probably the best way to do this would be to make your NonDB field a calculated field and then setEnabled from RowSelected.
https://www.acumatica.com/blog/using-the-pxformula-attribute-to-simplify-your-code/
Otherwise, create a BQl query in FieldDefaulting.

JavaFX 2.0: What do I have to do to react on a row selection change in a table?

I want to do a very easy and common thing but don't find a way to do it with JavaFX.
I have a TableView with two columns and want to enable a button if at least one row is selected. If no row is selected I want to disable the button again.
For that I need to get a selection changed event or something like that. Shouldn't be there a possibility to set the selectionModel of the tableView on action or add a listener to it?
What do I have to do?
I think what you will want to do is add a ListChangeListener to the selected indices on the selection model of your TableView. It should go something like this...
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); // just in case you didnt already set the selection model to multiple selection.
tableView.getSelectionModel().getSelectedIndices().addListener(new ListChangeListener<Integer>()
{
#Override
public void onChanged(Change<? extends Integer> change)
{
if (change.getList().size() >= 2)
{
button.setDisable(false);
}
else
{
button.setDisable(true);
}
}
});
I was originally going to suggest binding the disable property of the button to a selected indices property size on the table view being greater than 2, but there doesn't seem to be one provided. If you wanted to, you could create your own SimpleIntegerProperty and update it inside of the list change listener, binding the disable property of the button to the value of your SimpleIntegerProperty being greater than 2. I hope this answer is helpful!
An other solution in one line using the Property :
myButton.disableProperty().bind(myTable.getSelectionModel().selectedItemProperty().isNull());
That way, the button is enable when there is at least one line selected

Resources