In the package XML, all objects have the deployment action set to "Default":
When attempting to deploy a package with PowerShell, the following error is shown:
But the package can be deployed with Package and Deployment tool.
In general, K2 will compare the GUID, System Name, and Display Name of each object in the package with the one on the target environment to determine if the same object in the package already exists on the target environment. System Name must be unique across all objects, but it is possible to have multiple objects with the same Display Name.
Validation patterns are a little different as they only have a name and GUID. Each validation pattern will have a unique GUID and name.
When deploying a package with the Package and Deployment tool, the default action that gets chosen for an object will depend on whether the object is found on the target environment. If the same object exists on the target environment, the Package and Deployment tool will default to using the existing object instead of deploying the object in the package. There are options to force the Package and Deployment tool to deploy that object.
The same logic also applies to packages deployed with PowerShell. If the same object already exists on the target environment, K2 will not deploy that object.
Using the same logic, the error shown above should not appear in the first place as K2 should have detected the validation pattern on the target environment and not deploy it.
But upon further investigation, the GUID of the validation pattern on the source environment where the package was created from, and the GUID of the pattern on the target environment, is different.
In such scenario, the Package and Deployment tool will look at the name and determine that the pattern in the package is the same as the one on the target environment, so it sets the default action for the pattern to "Use Existing ValidationPattern". There are no other option on the Package and Deployment tool to deploy the pattern, except for using the pattern on the target environment.
When deploying the package with PowerShell, the behavior is different. The validation pattern in the package is determined to be different from the pattern on the target environment, so the default action is to deploy the pattern. But because a pattern with the same name already exists on the target environment, an error on the validation pattern will be shown.
To ensure this error does not show up again when deploying a package containing this validation pattern with PowerShell, make sure the GUID of this validation pattern on both the source and target environment matches.
Make sure no other changes, or new objects are created on the target environment. Changes should be made on the source environment, then create a package of the items, and deploy the package to the target environment. This will ensure the objects' GUID, System Name and Display Name are synchronized across both environments.
If faced with the error shown above, you can delete the validation pattern on the target environment, and redeploy a package containing the validation pattern. This ensures the same pattern will get recreated on the target environment, with the same GUID as the pattern on the source environment.
After redeploying the validation pattern, edit the forms and views that use that validation pattern, and check if the validation pattern is still being mapped properly. If not, reselect the validation pattern and check in the forms or views.