PACX (Greg.Xrm.Command)
repository·master·Indexed 41 days ago
https://github.com/neronotte/greg.xrm.commandAn open-source command-line utility belt for Microsoft Dataverse that extends the Power Platform CLI (PAC CLI). It provides automation commands for managing Dataverse organizations, solution components, Custom API lifecycles, and plugin steps, as well as tools for querying records via FetchXML, SQL, and OData.
What's inside PACX
- Greg.Xrm.Command.Core is the underlying engine for the Greg.Xrm.Command CLI tool. It is designed to be used as a library, allowing developers to import and execute Greg.Xrm.Command business logic directly within their own applications.
Overview of Greg.Xrm.Command (PACX)
masterGreg.Xrm.Command (also known as PACX) is a command-line utility belt designed for Microsoft Dataverse. It provides a set of specialized commands to perform operations that are not currently supported by the standard Power Platform CLI, such as performing dependency checks and manipulating the Dataverse datamodel.How field type conversion works in `pacx data create`
masterThe
pacx data createcommand automatically converts raw input strings into the appropriate Dataverse SDK types by inspecting the target table's metadata.Supported Conversions
- Strings/Memo: Handled as standard strings.
- Numbers:
IntegerAttribute(int),DecimalAttribute(decimal),DoubleAttribute(double), andMoneyAttribute(newMoneyobject). - Booleans: Parsed as
bool. - Date/Time:
- If the attribute is configured as
DateOnly, it parses asDateOnly(time set to 00:00:00). - Otherwise, it parses as
DateTimeusing ISO 8601 format.
- If the attribute is configured as
- Picklists (Choices):
- Single-select: If the input is an integer, it creates an
OptionSetValue(int). If it is a string, it searches for a matching label in theOptionMetadata. - Multi-select: Input values separated by commas are converted into an
OptionSetValueCollection.
- Single-select: If the input is an integer, it creates an
- Lookups: Resolved via the
LookupReferenceParserinto anEntityReference.
Limitations
- File/Image Fields: Fields of type
FileAttributeorImageAttributeare skipped and cannot be set via this command. You will see a non-blocking warning:Field 'x' is of type File/Image and will be skipped.
Resolve lookup references in `pacx data create`
masterWhen creating records, you can resolve lookup fields using two different syntaxes. This allows you to either provide a direct GUID or query for a record based on a specific field value.
Syntax Options
- Direct GUID: Use
entity(GUID)to point directly to a known record. - Field-based Query: Use
entity(fieldname='value')to resolve a record where the specified field matches the value. The command performs aRetrieveMultipleAsyncquery to find the record.
Rules and Constraints
- Ambiguity: If a field-based query returns 0 records, the command fails. If it returns 2 or more records, the command fails with an 'ambiguous value' error. It must return exactly 1 record.
- Escaping: To include a single quote within a field value, use two single quotes (
''). For example,name='Riccardo''s Corp'. - Polymorphic Lookups: For fields like
customerid(which can be anaccountor acontact), specify the target entity name explicitly, e.g.,account(accountnumber='ACME001')orcontact(emailaddress1='user@example.com').
pacx data create -t account --plain "name=Acme Corp;ownerid=systemuser(domainname='mario.rossi@contoso.com')" pacx data create -t incident --plain "title=Support Case;customerid=account(accountnumber='ACME001')"- Direct GUID: Use
Compare `data create` vs `data update`
masterWhile both commands share the same parsing and lookup resolution logic via the
RecordPayloadProcessor, they differ in several key ways:Aspect data createdata update--idparameterOptional (assigns GUID to new record) Mandatory (identifies record to update) SDK Operation IOrganizationService.Create()IOrganizationService.Update()Read-only fields IsValidForCreate == false→ warning + skipIsValidForUpdate == false→ warning + skipOutput GUID of created record GUID of updated record --returnRetrieve after Create Retrieve after Update Extend PACX with custom Tools
masterPACX is designed with a plugin-based approach similar to XrmToolbox. You can extend its capabilities by creating your own Tools.
A Tool is a set of PACX commands packaged into a single
.dllfile. These can be:- Deployed locally for specific single-use scenarios.
- Published to NuGet to make them available to the community.
This is the recommended method for adding context-specific commands to the platform.
Use PACX in Interactive mode
masterPACX features an interactive mode that provides a CLI-style UI for easier command discovery and execution.
Key features of interactive mode include:
- Navigation: Move through the command tree (upwards and downwards).
- Search: Find specific commands and namespaces.
- Execution: Run commands directly from the UI.
- Help: Access inline help for commands/namespaces and on-demand help for specific options using
/?. - Readability: Colorized output.
pacx --interactiveManage Dataverse organization and languages
masterUse the
pacx orgcommand group to manage your Dataverse environment settings without using the Maker Portal. You can retrieve environment summaries withorg infoand manage supported languages programmatically usingorg language. This is useful for automated environment setup and managing multilingual deployments.Key commands:
pacx org info: Get a summary of the current environment.pacx org language list: List current languages.pacx org language add --lcid <LCID>: Add a language using its Locale ID.pacx org language remove --lcid <LCID>: Remove a language.
pacx org info pacx org language list pacx org language add --lcid 1040 pacx org language remove --lcid 1040Manage solution components
masterThe
pacx solution componentcommand group allows for programmatic management of components within Dataverse solutions. This is ideal for scripting solution reorganizations or automated deployments.Key commands:
pacx solution component addTable --solution <Name> --table <TableName>: A convenience wrapper to add an entire table to a solution.pacx solution component moveAll --fromSolution <Src> --toSolution <Dest> --componentType <Type>: Moves all components of a specific type between solutions.pacx solution component types: Lists the numeric component type codes recognized by PACX.pacx solution component add/remove/move: Standard operations for individual components using their GUIDs.
pacx solution component add --solution MySolution --componentType 1 --componentId <guid> pacx solution component move --fromSolution SolutionA --toSolution SolutionB --componentId <guid> pacx solution component moveAll --fromSolution SolutionA --toSolution SolutionB --componentType 1 pacx solution component remove --solution MySolution --componentId <guid> pacx solution component removeAll --solution MySolution --componentType 1 pacx solution component types pacx solution component addTable --solution MySolution --table contactManage user settings
masterManage Dataverse user settings via the CLI. This is useful for toggling specific settings across environments during deployment or testing.
Key commands:
pacx usersettings list: List all available user setting definitions.pacx usersettings set --uilanguageid <ID>: Change a value for the current user in the current environment.
pacx usersettings list pacx usersettings set --uilanguageid 1040Manage the Custom API lifecycle
masterThe
pacx customapicommand group provides full lifecycle management for Custom APIs, which are essential for exposing business logic to agents and connectors.Creation
- Global API:
pacx customapi create --unique-name <Name> --display-name <Name> --solution <Name> - Bound API:
pacx customapi create --unique-name <Name> --display-name <Name> --binding-type Entity --bound-entity <EntityName> --solution <Name>- Note:
--unique-nameis optional; if omitted, PACX infers it from the display name and solution prefix.
- Note:
Evolution and Inspection
- Parameters/Responses: Use
add-param/remove-paramandadd-response/remove-responseto evolve the API contract incrementally. - Inspection:
pacx customapi list --fullshows the complete signature (names, types, directions). - Documentation:
pacx customapi describe --unique-name <Name> --generate-input-file --generate-schema-filecreates local JSON templates and schemas.
Execution and Binding
- Run:
pacx customapi run --unique-name <Name> --input-file <Path> - Bind:
pacx customapi bind --api <Name> --plugin <PluginType> - Delete:
pacx customapi delete --unique-name <Name>
# Create a global Custom API pacx customapi create --unique-name myp_MyAction --display-name "My Action" --solution MySolution # Create a bound Custom API (entity binding) pacx customapi create --unique-name myp_MyAction --display-name "My Action" \ --binding-type Entity --bound-entity contact --solution MySolution # Add parameters and response properties pacx customapi add-param --api myp_MyAction --param InputName:String pacx customapi add-response --api myp_MyAction --response OutputResult:String # Inspect it pacx customapi list --full pacx customapi describe --unique-name myp_MyAction --generate-input-file --generate-schema-file # Execute it pacx customapi run --unique-name myp_MyAction --input-file input.json # Bind to a plugin pacx customapi bind --api myp_MyAction --plugin MyPlugin.MyType # Clean up pacx customapi remove-param --api myp_MyAction --name InputName pacx customapi delete --unique-name myp_MyAction- Global API:
Manage Web Resource environment images
masterThe
pacx wr setEnvImagecommand (aliases:setLogo,setOrgImage) manages environment branding using the modernCustomThemeDefinitionflow. This allows for version-controlled environment configurations.Key commands:
- Set Org Logo:
pacx wr setEnvImage --name <FileName> --color <HexColor> - Set App Logo:
pacx wr setEnvImage --name <FileName> --appName <AppName> - Sync to Local File:
pacx wr setEnvImage --file <FileName> --localThemeFile <Path>- Use
--localThemeFileto keep a local XML theme file in sync with the deployed environment, enabling reproducible themes across environments.
- Use
# Set the org-level logo for the first time pacx wr setEnvImage --name mylogo.png --color "#0078D4" # Update the logo for a specific app pacx wr setEnvImage --name mylogo.png --appName "My Model App" # Sync the theme to a local file for version control pacx wr setEnvImage --file mylogo.png --localThemeFile ./theme.xml- Set Org Logo: