web
You’re offline. This is a read only version of the page.
close
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

Change owner only when conditions are met

(0) ShareShare
ReportReport
Posted on by 45

Hi

I received an interesting requirement to implement but not sure if its possible.

What we have:

  • two security roles, Agent and Manager
  • leads are coming in Dynamics through website and assigned to default user Admin (System Administrator role)

What is required:

  • Agents should be able to assign Opportunity to themselves only and only if current owner is Admin
  • If current owner is not Admin, changing owner should be disabled
  • Managers can reassign Opportunities without any limitations

Right now I was able to limit Agent role to disable assigning owners completely, but can't find a way to allow it just under specific conditions.

Please feel free to share your ideas.

Thanks.

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    afaik you will need a plugin to implement this scenario

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Guido mentioned that you can do it via plugin and I second this but you can do it using Real-Time Workflow as well.

    The action to handle with the workflow is "Assign" and in order to check the roles of users you can use one of the free custom workflow activities toolkits (for example my toolkit - a reference to it is available in the signature) and if it's not allowed to reassign - just stop the workflow with an error. You can see an example here - gtcrm.wordpress.com/.../

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"

  • vahrameev Profile Picture
    45 on at

    Thank you Andrew.

    Sorry my response took so long, we had a major release and I was involved in that.

    I'm not an experienced Dynamics user and I'm sure I could use your response to solve my problem, but sadly for now I'm not exactly sure how to implement it.

    Had to go with the script:

    function disable_owner_change() {
        setTimeout(function () { // Had to set timeout because form was loading slow and can't get the OwinerID
            var roleId = '2a0f75b3-8f50-ea11-a883-000d6a8bfcc8'; // Agent RoleID
            var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.securityRoles; // Get current user security roles
            var userRoleId = currentUserRoles[0]; // Getting the first role (and the only role in my case)
            if (userRoleId == roleId && currentUserRoles.length == 1) { // Checking if current user is Agent and it's the only role
                var OwnerIDorig = Xrm.Page.getAttribute("ownerid").getValue()[0].id; // Check the current Opportunity owner role
                var OwnerID = OwnerIDorig.toString();
                if (OwnerID == "{78F45BC3-4E75-EA54-A823-000D3A30F547}" || OwnerID == "{65564BC7-E593-EA12-A871-000D3A76E885}") { // Check if current Opportunity owner is Admin (in dev or prod env)
                    Xrm.Page.getControl("header_ownerid").setDisabled(false);
                }
                else {
                    Xrm.Page.getControl("header_ownerid").setDisabled(true);
                }
            }
        }, 3000);
    }

    I'm pretty sure it's not the elegant script version but had no time to dig it up.

    Please fill free to modify it or suggest an edit, will be glad to use it.

    Thanks.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans