Optimize Acumatica Development with a Snippet
Hello, everyone!
Today, I want to share a technique that can significantly simplify your daily routine in Acumatica development: using custom Visual Studio snippets. Snippets are pre-written pieces of code that you can insert quickly, saving you time and reducing errors. In this article, I’ll explain how to create and use custom snippets for Acumatica field properties, graph extensions and DAC templates.
Setting Up Your Snippets
- Create a Snippets Folder: First, create a dedicated folder to store your snippets. For example: C:\Users\YourName\Documents\Visual Studio 2019\Code Snippets\Visual C#\My Code Snippets.
- Open Visual Studio: Go to Tools > Code Snippets Manager, select C# as the language, and add your new folder.
- Add Snippet File: Copy and paste the XML snippet file provided at the end of this article into the new folder. Visual Studio will recognize these snippets, and they will be ready to use in your code editor.
- Using the Snippets: In your C# files, simply type the snippet shortcut (such as dacint), press Tab, and the snippet will expand.
My Snippet Reference Table
Here’s a table of the snippets we’re adding by default and of course in the future you can add your own depending on your needs.
Along with what they look like in the code:
dacint |
public virtual int? FieldName { get; set; } public abstract class FieldName : BqlInt.Field<FieldName> {} |
dacbool |
public virtual bool? FieldName { get; set; } public abstract class FieldName : BqlBool.Field<FieldName> {} |
dacstring |
public virtual string FieldName { get; set; } public abstract class FieldName : BqlString.Field<FieldName> {} |
dacdecimal |
public virtual decimal? FieldName { get; set; } public abstract class FieldName : BqlDecimal.Field<FieldName> {} |
dacdouble |
public virtual double? FieldName { get; set; } public abstract class FieldName : BqlDouble.Field<FieldName> {} |
dacdate |
public virtual DateTime? FieldName { get; set; } public abstract class FieldName : BqlDateTime.Field<FieldName> {} |
dacguid |
public virtual Guid? FieldName { get; set; } public abstract class FieldName : BqlGuid.Field<FieldName> {} |
dactemplate |
Inserts all required audit fields: CreatedByID, CreatedDateTime, LastModifiedByID, Tstamp, etc. |
graphext |
public class GraphExtension : PXGraphExtension<GraphName> { public static bool IsActive() => true; } |
Full Snippet XML
Below is the full XML code for the snippets.
https://drive.google.com/file/d/16gw3PFaGuV4eaQGOFsJQKpEZdXtCah3r/view?usp=sharing
Copy and paste this XML into .snippet file, and save it in the folder you created.
With these snippets, your Acumatica field setup will be faster and more standardized, making the development process smoother and error-free. Happy coding!