Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Auto Publish an Ai Model using Power Automate

(2) ShareShare
ReportReport
Posted on by 9
I have developed a prediction model using Power Apps and subsequently created a Power Automate flow for retraining the model. Now, I aim to automatically publish the retrained model. Although I am utilizing the "Perform an unbound action" trigger for this purpose, it is failing to publish the retrained model. How I can auto-Publish the model?


  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,026 Super User 2025 Season 1 on at
    Auto Publish an Ai Model using Power Automate
    Since using the PublishAIModel unbound action is not resulting in the newly retrained version being published—even though the model name gets updated—this confirms that:
    The PublishAIModel action targets the AI model entity, but does not publish the latest training run/version unless explicitly instructed.
    The updated model version (produced by retraining) lives in the mlmodeltraining table and must be published using its specific training run ID, not just the model ID.

    Final Working Solution: Publish a Specific Trained Model Version
    🔧 Step 1: Retrieve the Latest Successful Training Run
    Use “List rows” on mlmodeltraining with:
    • Filter Query:
    nginx CopyEdit
    _modelid_value eq 'YOUR_MODEL_ID' and statuscode eq 192350003
    (192350003 = “Succeeded”)
    • Order By:
    sql   CopyEdit
    createdon desc
    • Top Count:
    CopyEdit
    1
    From the returned row, extract the mlmodeltrainingid (GUID of the successful retraining run).

    🔧 Step 2: Use HTTP Request to Publish That Version
    Use a custom HTTP request to call the PublishTrainingRun action directly on that training ID:
    • Action: Invoke an HTTP request (Dataverse connector)
    • Method: POST
    • URL:
    bash   CopyEdit
    /mlmodeltrainings(<mlmodeltrainingid>)/Microsoft.Dynamics.CRM.PublishTrainingRun
    This explicitly publishes that specific trained version.
    ️ Do not use PublishAIModel—it doesn’t guarantee the latest version gets published.

    🧪 Example Use in Flow (Summary)
    1. Trigger: Manual or Scheduled.
    2. Action: Train the model (if not already trained).
    3. List rows: From mlmodeltraining, filter by modelid, status Succeeded.
    4. Get first row: Extract the training run ID.
    5. HTTP Request:
      • Method: POST
      • URL:
    bash  CopyEdit
    /mlmodeltrainings(<training_run_id>)/Microsoft.Dynamics.CRM.PublishTrainingRun
    1. Success notification.

    🔍 Notes
    • You must use the Dataverse connector with HTTP support (not the legacy HTTP connector unless OAuth is handled manually).
    • Make sure the user or flow connection has AI Builder Admin privileges and rights on the mlmodeltraining table.
    • AI Builder does not expose this publish action in the UI or flow library—you have to trigger it via direct API.

    Would you like a ready-to-import Power Automate package with this logic, or guidance on setting up the HTTP step securely?
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,318 Super User 2025 Season 1 on at
    Auto Publish an Ai Model using Power Automate
  • Zaki Profile Picture
    9 on at
    Auto Publish an Ai Model using Power Automate
    @Saif Ali Sabri  I followed the approach you suggested, but the issue persists. Despite providing all the correct details, running the PublishAiModel trigger changes the name, yet the newly retrained model does not get published.
     
  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,026 Super User 2025 Season 1 on at
    Auto Publish an Ai Model using Power Automate
    To auto-publish a retrained AI model in Power Platform using Power Automate, you must ensure the correct configuration of the Dataverse unbound action and meet all necessary prerequisites for model publishing.

    Solution: Auto-Publish a Retrained AI Model in Power Automate
    Here’s a step-by-step approach to resolve the issue and successfully publish the retrained model:

    1. Confirm the Model Training Status
    Ensure the retrained model has completed successfully before publishing. You can:
    • Use the List records action on the mlmodeltraining table.
    • Filter based on the model ID and retrieve the latest training run.
    • Check the statuscode field. It must be “Succeeded” (value: 192350003) before attempting to publish.

    2. Use the Correct Unbound Action
    The correct unbound action for publishing a model is:
    CopyEdit
    Microsoft.Dynamics.CRM.PublishAIModel
    But this unbound action is not directly exposed in Power Automate’s UI. You’ll need to use the "Perform an unbound action" with the correct parameters.

    3. Setup: Perform an Unbound Action in Power Automate
    • Action: "Perform an unbound action"
    • Action Name: PublishAIModel
    • Parameters (in JSON format):
    json
    CopyEdit
    {
      "ModelId": "GUID of your AI model"
    }
    • Replace GUID of your AI model with the actual GUID of your model.

    4. Ensure Required Permissions
    Ensure the user or service principal running the flow has:
    • AI Builder Admin or equivalent role.
    • Full access to Dataverse tables related to AI models (mlmodel, mlmodeltraining, etc.).

    5. Add Retry/Delay Logic
    There may be a lag between model retraining and readiness for publishing. To handle this:
    • Add a delay before the publish action (e.g., wait 5 minutes).
    • Or, loop and poll the mlmodeltraining status every minute until it’s “Succeeded”.

    6. Error Handling
    If the action fails:
    • Capture the detailed error message using Configure Run After > has failed.
    • Use Compose to log the error for debugging.

    🧪 Sample Flow Logic
    1. Trigger: Manual or scheduled.
    2. Step 1: Retrain model.
    3. Step 2: Wait for training completion (loop until statuscode == 192350003).
    4. Step 3: Use Perform an unbound action with PublishAIModel.
    5. Step 4: Notify success or failure.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 72

Overall leaderboard

Product updates

Dynamics 365 release plans