Acumatica offers a great feature to Save as Template which makes creating new records from the template faster and easier. However, I have a use case where I need a more interactive sort of template in which the user can create a list of 100 items and then select which items to include when creating the new record.
In this case, the standard feature for Save as Template could be confusing, especially for new users learning the system. I have been asked to disable Save as Template on the Copy/Paste menu on my custom screen and transition to this new feature. I do not want to disable Copy/Paste entirely, just the Template functionality. If I disable Copy/Paste in Access Rights, the entire menu disappears. However, the template options do not appear in Access Rights.
Copy/Paste appears to be accessible via code as the PXAction CopyPaste which can be hidden or disabled, but again, I cannot find SaveTemplate as a child that I can control.
How can I disable/hide Save as Template (CopyPaste#SaveTemplate) on an Acumatica screen, either programmatically, in access rights, or in workflow? This menu is part of the standard Acumatica menu system when specifying a primary DAC when defining the graph. Alternatively, I think it enabled via the PXCopyPasteAction<> action if manually defining buttons on the page.
You can create your own PXCopyPasteAction by just extending the base class and then adding it to your graph
quick example below
public class CustomCopyPasteAction: PXCopyPasteAction<SOOrder>
{
public CustomCopyPasteAction(PXGraph graph, string name): base(graph, name) { }
protected override void RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
base.RowSelected(cache, e);
bmSaveTemplate.Enabled = false;
}
}
The CopyPaste action is coming predefined as part of the PXGraph<TGraph,TPrimary> class. So you should be able to just simply do CopyPaste.SetEnabled(false) in the RowSelected event handler of your graph.
Another option is to try to override the CanClipboardCopyPaste virtual function of the PXGraph class.
public class PXGraph<TGraph, TPrimary> : PXGraph where TGraph : PXGraph where TPrimary : class, IBqlTable, new()
{
public override bool CanClipboardCopyPaste()
{
return true;
}
/// <summary>The action that saves changes stored in the caches to the database. The code of an application graph typically saves changes through this action as well. To invoke it from code, use the PressSave() method of the Actions property.</summary>
public PXSave<TPrimary> Save;
/// <summary>The action that discard changes to the data from the caches.</summary>
public PXCancel<TPrimary> Cancel;
/// <summary>The action that inserts a new data record into the primary cache.</summary>
public PXInsert<TPrimary> Insert;
/// <summary>The action that deletes the Current data record of the primary cache.</summary>
public PXDelete<TPrimary> Delete;
/// <summary>The action that is represented on the user interface by an expandable menu that includes Copy and Paste items.</summary>
public PXCopyPasteAction<TPrimary> CopyPaste;
/// <summary>The action that navigates to the first data record in the primary data view. The data record is set to the Current property of the primary cache.</summary>
public PXFirst<TPrimary> First;
/// <summary>The action that navigates to the previous data record in the primary data view. The data record is set to the Current property of the primary cache.</summary>
public PXPrevious<TPrimary> Previous;
/// <summary>The action that navigates to the next data record in the primary data view. The data record is set to the Current property of the primary cache.</summary>
public PXNext<TPrimary> Next;
/// <summary>The action that navigates to the last data record in the primary data view. The data record is set to the Current property of the primary cache.</summary>
public PXLast<TPrimary> Last;
}
Related
Lets say I have a graph as follows
public PXCancel<DAC1> Cancel;
public PXSave<DAC1> Save;
public PXSelect<DAC1> View;
public PXSelect<DAC2> Entities;
public PXSelect<DAC3> Mappings;
Currently, when a change is made to the data view of DAC2, when the save button is pressed, nothing is persisted (even though the save button becomes enabled on the UI once the change is made). Once I make a change to DAC1, then the changes to both DAC1 and DAC2 are persisted successfully.
How can I make it so that when only a change to DAC2 is made, the save button works?
You can try marking the record of the DAC1 as updated in the cache when the record of the DAC2 or DAC3 is updated.
graph.Caches[typeof(DAC1)].MarkUpdated(record);
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.
I would like to filter the records shown on the Projects screen. I've been given the directive to see if limiting the Selector for projects (re-writing the PXSelector for the ProjectID?) would also limit the records that show up on the screen, i.e., a user would not be able to navigate to records that aren't displayed by the Selector. I don't think that's the case, as the screen's view is not limited by what is chosen by the Selector - but I wanted to verify this.
Also - as far as limiting the records that show up in the Selector (possibly re-writing the Selector/BQL using a where clause?) - I looked at the source DAC, and for the life of me I can't figure it out. There is a PXSelector on the ContractID, which doesn't use the SubstituteKey that I'm familiar with, and the ContractCD also has several attributes with which I'm unfamiliar - namely the PXRestrictor AND the PXDimensionSelector.
Bottom line:
1.) What's the best way to limit the records for Project shown in the screen's Selector? Can I just add to the PXRestrictor attribute?
2.) Would limiting the Selector's results also limit what the user can navigate to on the screen using the navigation buttons?
Whenever you need to restrict access to primary records on a data entry screen, it's always required to customize both the lookup DAC key field and the primary data view. By design, in Acumatica key fields in DAC and the primary data view are completely independent, that is why it's required to modify both pieces to achieve the desired result.
For example, to deny access to canceled projects on the Projects screen, you should add PXRestrictorAttribute to PMProject's ContractCD field and also re-declare Project primary data view:
public class ProjectEntryExt : PXGraphExtension<ProjectEntry>
{
public class cancelled : Constant<string>
{
public cancelled() : base(ProjectStatus.Cancelled) {; }
}
[PXViewName(Messages.Project)]
public PXSelect<PMProject, Where<PMProject.baseType, Equal<PMProject.ProjectBaseType>,
And<PMProject.nonProject, Equal<False>, And<PMProject.isTemplate, Equal<False>,
And<PMProject.status, NotEqual<cancelled>,
And<Match<Current<AccessInfo.userName>>>>>>>> Project;
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<PMProject.status, NotEqual<cancelled>>),
"Given Project/Contract '{0}' is cancelled", typeof(PMProject.contractCD))]
public void PMProject_ContractCD_CacheAttached(PXCache sender) { }
}
I would like to use logical deletion in a custom screen and I have added the following to my DAC:
#region DeletedDatabaseRecord
public abstract class deletedDatabaseRecord : PX.Data.IBqlField
{
}
protected bool? _DeletedDatabaseRecord;
[PXDBBool()]
[PXDefault(false)]
public virtual bool? DeletedDatabaseRecord
{
get
{
return this._DeletedDatabaseRecord;
}
set
{
this._DeletedDatabaseRecord = value;
}
}
#endregion
The above DAC is used in a grid (in a master/detail screen). When I click on the grid delete and then save, the row gets marked as deleted in the database.
However, when I refresh the screen, the deleted rows appear again. It seems that the data view is not taking into DeletedDatabaseRecord value. I confirmed that this was set to 1 in the database.
My data view is as follows:
public PXSelect<DCRule, Where<DCRule.ruleHeaderID, Equal<Current<DCRuleHeader.ruleHeaderID>>>, OrderBy<Asc<DCRule.sequence>>> Rules;
Shouldn't the data view, automatically filter out deleted records (where DeletedDatabaseRecord = 1)? or should I handle something else in the code logic.
UPDATE 1
I have removed the DeletedDatabaseRecord from the DAC as the Design Guidelines state that they should not be included. However, I am still having the exact same issue.
UPDATE 2
I also noticed that the SQL statement is not filtering out the deleted records, and it is also not returning it as a column.
Add CompanyID column to the table where you use DeletedDatabaseRecord. After that deleted row should not appear.
One should never declare DAC fields for the following columns:
CompanyID
CompanyMask
DeletedDatabaseRecord
When you make some to Acumatica database schema, it's always a good practice to restart IIS or recycle the app pool hosting your Acumatica website, so Acumatica can re-sync the updated DB schema during domain restart as it does not track database schema changes at runtime.
I have created a new CREATE QUOTE button on Requisition screen that replace the standard button which located at Action menu. After trying to hide it on RQRequisition_RowSelected event, the button still appear and able to click when the requisition is on Pending Quote Status. Kindly need advice how to hide it.
Customized Requisition Screen
To hide or show an action button, you should redefine the Visible parameter of the PXUIField attribute for the button.
You can change attributes of an action button by using one of the following approaches:
Dynamically at run time, in the Initialize() method of the graph
extension
Statically, by overriding the action attributes in the
graph extension
To Hide an Action Button at Run Time
In the graph extension, add the following code.
public override void Initialize()
{
base.Initialize();
Base.MyAction.SetVisible(false);
}
In the added code, replace MyAction with the action name.
To Hide or Show an Action Button Statically
To override action attributes in a graph extension statically, you should declare both the graph member of the PXAction type and the delegate. You should attach a new set of attributes to the action delegate, declared within the graph extension. Also, you need to invoke the Press() method on the base graph action. Having redeclared the member of PXAction, you prevent the action delegate execution from infinite loops.
Explore the original action declaration and copy the declaration to the graph extension.
In the action declaration, set to false the Visible parameter of the PXUIField attribute, as the following code snippet shows.
...
[PXUIField(…, Visible = false)]
...
Replace the action delegate with the following code template.
public virtual IEnumerable myAction(PXAdapter adapter)
{
return Base.MyAction.Press(adapter);
}
In the code template, replace myAction and MyAction with the appropriate names.
In the template, redefine the action delegate arguments and return type according to the signature of the base action delegate.
If you have a customization that replaces an original action
declaration statically, after upgrading Acumatica ERP to a new
version, a new functionality of the same action may became
unavailable.
Also, if a callback command for the button is declared in the PXDataSource control, you can hide the button by customizing the ASPX code. To do this, in the Layout Editor, expand the PXDataSource control, select the appropriate PXDSCallbackCommand element, and set to False the Visible property of the element.
CREATE QUOTE button on the Requisition screen is implemented like a normal action in the RQRequisitionEntry BLC:
public class RQRequisitionEntry : PXGraph<RQRequisitionEntry>
{
...
public PXAction<RQRequisition> createQTOrder;
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
[PXUIField(DisplayName = Messages.CreateQuotation)]
public virtual IEnumerable CreateQTOrder(PXAdapter adapter)
{
...
}
...
}
However, CREATE QUOTE button is added into the Actions drop down via Automation Steps:
With that said, the best way to customize the CREATE QUOTE button is by re-declaring the action within the RQRequisitionEntry BLC extension following sample below. I would be happy to come up with a more specific sample, if you provide additional details regarding your request.
public class RQRequisitionEntryExt : PXGraphExtension<RQRequisitionEntry>
{
public PXAction<RQRequisition> createQTOrder;
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
[PXUIField(DisplayName = RQ.Messages.CreateQuotation)]
public virtual IEnumerable CreateQTOrder(PXAdapter adapter)
{
return Base.createQTOrder.Press(adapter);
}
}