Skip to content

Fix: Environment variable updates fail silently with 400 constraint violation#10832

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-environment-variable-update
Draft

Fix: Environment variable updates fail silently with 400 constraint violation#10832
Copilot wants to merge 5 commits intomainfrom
copilot/fix-environment-variable-update

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

CoE Admin Command Center attempts POST to create new EnvironmentVariableValue records when updating existing values, triggering unique constraint violations on environmentvariabledefinitionid. UI shows success; save fails silently.

Changes

OnButtonSelect (Save handler)

  • Add fresh LookUp() to determine record existence before save operation
  • Route to Patch(existingRecord) for updates vs Patch(Defaults()) for creates
  • Add IsError() check with FirstError() user notification
  • Keep panel open on error for retry

OnVisible (Initialization)

  • Replace placeholder GUID with Blank() for CurrentID
  • Fix hasCurrent to check record existence: !IsBlank(envVarValue) instead of !IsBlank(envVarValue.Value)
  • Use With() for cleaner lookup pattern

Code

// Before: stale flag check, always POST on false
If(EnvVarsList.Selected.hasCurrent = true,
    UpdateIf('Environment Variable Values', ...),
    Patch(..., Defaults(...), ...)  // Fails if record exists
);
Set(Loader, false);
UpdateContext({showPanel: false});  // Closes regardless

// After: fresh lookup, route to PATCH or POST, handle errors
Set(existingEnvVarValue, LookUp('Environment Variable Values', ...));
If(!IsBlank(existingEnvVarValue),
    Set(saveResult, Patch(..., existingEnvVarValue, {Value: ...})),
    Set(saveResult, Patch(..., Defaults(...), {Value: ...}))
);
If(IsError(saveResult),
    Notify("Error: " & FirstError(saveResult).Message, Error);
    Set(Loader, false),  // Keep panel open
    Notify("Success", Success);
    Set(Loader, false);
    UpdateContext({showPanel: false})
);

Impact

  • Binary diff only (.msapp file: 224KB → 230KB)
  • Manual testing required in Power Apps Studio (test plan included)
  • No breaking changes; revert functionality unchanged

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/curl curl -L REDACTED -o pac-cli.tar.gz (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: CoE Admin Command Center fails silently with 400 error when updating environment variable (database constraint violation)</issue_title>
<issue_description>### Does this bug already exist in our backlog?

  • I have checked and confirm this is a new bug.

Describe the issue

When attempting to set or update an environment variable via the CoE Admin Command Center (specifically admin_PowerPlatformMakeSecurityGroup), the UI displays a success message, but the action fails in the background.

The network trace reveals a 400 Bad Request from the Dataverse API. The application is attempting to create a new EnvironmentVariableValue record instead of updating the existing one, leading to a database unique constraint violation on environmentvariabledefinitionid.

App: CoE Admin Command Center

Steps to Reproduce
Open CoE Admin Command Center.

Navigate to Environment Variables.

Locate admin_PowerPlatformMakeSecurityGroup.

Enter a value and click save.

Notice the green "Success" notification in the PowerApp.

Check Browser DevTools (Network tab) to see the failed request.

Expected Behavior
The app should detect if a value already exists for the definition and perform an update (PATCH) instead of a create (POST), or at least reflect the API error in the UI.

Technical Details
Endpoint: https://.crm2.dynamics.com/api/data/v9.0/environmentvariablevalues

HTTP Status: 400

Error Code: 0x80072013

Message: Cannot complete the creation of EnvironmentVariableValue because it violates a database constraint. The violation happens on the key environmentvariabledefinitionid: 85f561e3-d49b-4f30-b459-d6fa623e6a94. Please delete the existing record or use update.

Exception Category: ClientError (ExportKeyInvalidCreate)

Screenshots / Logs
JSON
{
"error": {
"code": "0x80072013",
"message": "Cannot complete the creation of EnvironmentVariableValue because it violates a database constraint. The violation happens on the key environmentvariabledefinitionid: 85f561e3-d49b-4f30-b459-d6fa623e6a94. Please delete the existing record or use update.",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionMessageName": "ExportKeyInvalidCreate",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionHttpStatusCode": "400"
}
}

Expected Behavior

The app should detect if a value already exists for the definition and perform an update (PATCH) instead of a create (POST), or at least reflect the API error in the UI.

What solution are you experiencing the issue with?

Core

What solution version are you using?

4.50.6

What app or flow are you having the issue with?

CoE Admin Command Center

What method are you using to get inventory and telemetry?

None

Steps To Reproduce

  1. Open CoE Admin Command Center.
  2. Navigate to Environment Variables.
  3. Locate admin_PowerPlatformMakeSecurityGroup.
  4. Enter a value and click save.
  5. Notice the green "Success" notification in the PowerApp.
  6. Check Browser DevTools (Network tab) to see the failed request.

Anything else?

Technical Details
Endpoint: https://.crm2.dynamics.com/api/data/v9.0/environmentvariablevalues

HTTP Status: 400

Error Code: 0x80072013

Message: Cannot complete the creation of EnvironmentVariableValue because it violates a database constraint. The violation happens on the key environmentvariabledefinitionid: 85f561e3-d49b-4f30-b459-d6fa623e6a94. Please delete the existing record or use update.

Exception Category: ClientError (ExportKeyInvalidCreate)

Screenshots / Logs
JSON
{
"error": {
"code": "0x80072013",
"message": "Cannot complete the creation of EnvironmentVariableValue because it violates a database constraint. The violation happens on the key environmentvariabledefinitionid: 85f561e3-d49b-4f30-b459-d6fa623e6a94. Please delete the existing record or use update.",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionMessageName": "ExportKeyInvalidCreate",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionHttpStatusCode": "400"
}
}</issue_description>

<agent_instructions>Analyze why the CoE Admin Command Center (Core v4.50.6) tries to create a new EnvironmentVariableValue instead of updating the existing one when saving admin_PowerPlatformMakeSecurityGroup. The UI shows success, but Dataverse returns 400 (0x80072013) due to a unique‑constraint violation. Identify the faulty logic in the app’s save/Patch code and provide the fix so it performs a PATCH instead of POST, and correctly surfaces API errors to the user.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix silent failure when updating environment variable in CoE Admin Fix: Environment variable updates fail silently with 400 constraint violation Feb 10, 2026
Copilot AI requested a review from AmarSaiRam February 10, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CoE Admin Command Center fails silently with 400 error when updating environment variable (database constraint violation)

2 participants