Skip to main content

Notifications

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.

  • vahrameev Profile Picture
    45 on at
    RE: Change owner only when conditions are met

    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.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Change owner only when conditions are met

    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?"

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Change owner only when conditions are met

    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
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Change owner only when conditions are met

    afaik you will need a plugin to implement this scenario

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 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…

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 136 Super User 2025 Season 1

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 106

Overall leaderboard

Product updates

Dynamics 365 release plans