web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

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

How to Team Entity Lookup Field On Change to Set Grant Permission Privilege

(0) ShareShare
ReportReport
Posted on by 5

Hello All ,

I have create one lookup field in Order Entity and lookup field is Team (lookup entity is Team).

I am trying to Team lookup field on change to set Grant Permission Privilege for selected Team lookup field like Create Or Update Or Read.

Please help me its possible to JavaScript.

Many Thanks......

pastedimage1645175771177v1.png

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Vijay123,

    Permissions like Create Or Update Or Read for one entity are included in one security role, and Team has one N:N relationship with Security Role.

    pastedimage1645176455327v1.png

    So you can set correct permission for the entity in one security role, and associate the role with the team through web api.

    // NOTE: Associate Request in Xrm.WebApi supports multiple children, you can add them inside the relatedEntities array
    var associateRequest = {
    	target: { entityType: "team", id: "" },
    	relatedEntities: [
    			{ entityType: "role", id: "" }
    	],
    	relationship: "teamroles_association",
    	getMetadata: function () { return { boundParameter: null, parameterTypes: {}, operationType: 2, operationName: "Associate" }; }
    };
    
    Xrm.WebApi.online.execute(associateRequest).then(
    	function success(response) {
    		if (response.ok) {
    			console.log("Success");
    		}
    	}
    ).catch(function (error) {
    	console.log(error.message);
    });

    For the id of the security role, it is static, you can get it in the url.

    For the id of the team, you can get it in the lookup field(Team) through following code:

    var formContext = executionContext.getFormContext();
    // Getting the value of Case Owner
    var Team = formContext.getAttribute(“teamlogicname”).getValue();
    // Getting the GUID of the lookup record
    var Teamid = Team[0.id;

    You can build api easily through Dataverse REST Builder:

    New tool: Dataverse REST Builder ~ CRM Answers

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    I think your requirement is to share Order Record with Team.

    You can execute GrantAccess Action from Javascript to share Order record with selected Team in lookup.

    docs.microsoft.com/.../sample-share-records-using-grantaccess-modifyaccess-revokeaccess-messages

    docs.microsoft.com/.../grantaccess

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Vijay123 Profile Picture
    5 on at

    Hello   ,

    Thank you so much for give me the solution and sorry for late response because i am not available last few days.

    Another One question its possible to set Grant Permission Privilege for selected Team lookup and Team is Associated with Owner.

    Because i am trying to solve Grant Permission based on Owner and Owner is in Team.

    For Example ABC is Owner and ABC Owner is in XYZ Team.

    Please Help me and Thanks once again........

  • Vijay123 Profile Picture
    5 on at

    Hello Leah Ju,

    I am try this and also get the error.

    Code : 

    function OnChangeTeamPrivillage(executionContext) {
        debugger;
        var formContext = executionContext.getFormContext();
        // Getting the value of Case Owner
        var Team = formContext.getAttribute("emp_team").getValue();
        // Getting the GUID of the lookup record
        var Teamid = Team[0].id;

        // NOTE: Associate Request in Xrm.WebApi supports multiple children, you can add them inside the relatedEntities array
        var associateRequest = {
            target: { entityType: "team", id: Teamid },
            relatedEntities: [
                    { entityType: "role", id: "9ce12383-6a39-4252-9a02-e44b378bba15" }
            ],
            relationship: "teamroles_association",
            getMetadata: function () { return { boundParameter: null, parameterTypes: {}, operationType: 2, operationName: "Associate" }; }
        };

        Xrm.WebApi.online.execute(associateRequest).then(
            function success(response) {
                if (response.ok) {
                    console.log("Success");
                    alert("Success...");
                }
            }
        ).catch(function (error) {
            console.log(error.message);
            alert(error.message);
        });
    }

    pastedimage1645593942033v1.png

    i am check the this code in debug and not in success it is jump in   alert(error.message).

    Please help me and let you know i am also trying to Privilege Access from User and user in any Team and Team has a Some Security Role.

    For Example : ABC is Owner and ABC Owner is in XYZ Team and XYZ team has a Some Role(Ex. Test Role).

    So, If i am Update or Create Order Entity Record at that time ABC owner has no Privilege Access for create and Update.

    Thank you so much Leah Ja and Please help me.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 140 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans