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,...
Answered

Editing entity subgrid via query

(0) ShareShare
ReportReport
Posted on by 20

Hello,

I'm wondering if there is a way to modify a subgrid within an entity form using web api. I need a way to automatically change the contents of the team subgrid within the systemuser entity form from a separate dasbhoard. 

Or I need to know how to automatically create teammembership records (via web api POST or Xrm.WebApi.createRecord) to establish the relationship between systemuser and team. 

Thank you very much,

Scott  

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Scott,

    You won't be able to do it using Xrm.WebApi.createRecord but you would be able to do so using Xrm.WebApi.execute. You will have to use AddMembersTeam action - learn.microsoft.com/.../addmembersteam

    In order to make it easier you can use Dataverse Restbuilder for this purpose - github.com/.../DRB in order to get an example of JavaScript.

  • Scott Parks Profile Picture
    20 on at

    Hi Andrew,

    Thank you for your response. I apologize, I am not very familiar with how to use actions yet. I reviewed the js files from the github resource and I am not certain how this application utilizes AddMembersTeam.

    I also did not find any reference to Xrm.WebApi.online.execute. Would you mind providing me with a basic explanation/example to get me started?

    Thank you very much,

    Scott

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

    Scott,

    Here is the reference to Xrm.WebApi.execute - learn.microsoft.com/.../execute

    In order to compose the initial version of the code you can use Dataverse Rest Builder - it can be managed solution or plugin from XrmToolbox. Feel free to post here your updates or if you experience any issues.

  • Scott Parks Profile Picture
    20 on at

    Hi Andrew,

    I managed to put this together from the documentation:

       var Sdk = window.Sdk || {};

       Sdk.AddMembersTeamRequest = function(members, target) {

           this.entity = target;

           this.Members = members;

       }

       Sdk.AddMembersTeamRequest.prototype.getMetadata = function() {

           return {

               boundParameter: "entity",

               parameterTypes: {

                   "Members": {

                       "typename": "Collection(mscrm.systemuser)",

                       "structuralProperty": 4

                   }

               },

               operationType: 0,

               operationName: "AddMembersTeam"

           }

       }

       var members = [

           {

               "@odata.type": "Microsoft.Dynamics.CRM.systemuser",

               "ownerid":  userId

           }

       ];

       var target = {

           entityType: "team",

           id: teamId

       }

       var addMembersTeamRequest = new Sdk.AddMembersTeamRequest(members, target);

       // Use the request object to execute the function

       Xrm.WebApi.online.execute(addMembersTeamRequest).then(function (response) {

           debugger;

           if (response.ok) {

               console.log("Status: %s %s", response.status, response.statusText);

               // Perform other operations as required.

           }

       }).catch(function(error) {

           debugger;

           console.log(error.message);

           // handle error conditions

       });

    When I execute this code, I receive the error message: "Cannot read properties of undefined (reading 'structuralProperty')".  I looked in debugger and the getMetaData function was being invoked without issue, so I'm not sure why this would happen.

    Thank you again,

    Scott  

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

    Hello Scott,

    I used the tool that I mentioned earlier (Dataverse Rest Builder) and after a few clicks, I got the following:

    var execute_AddMembersTeam_Request = {
    	// Parameters
    	entity: { entityType: "team", id: "a4d13d63-9e40-ed11-9db0-6045bd8c9571" }, // entity
    	Members: [{ "@odata.type": "Microsoft.Dynamics.CRM.systemuser", systemuserid : "1cbbf53a-28dd-eb11-bacb-000d3abee4fc" }, { "@odata.type": "Microsoft.Dynamics.CRM.systemuser", systemuserid : "1d192b41-b0a5-eb11-b1ac-0022487fa90b" }], // Collection(mscrm.systemuser)
    
    	getMetadata: function () {
    		return {
    			boundParameter: "entity",
    			parameterTypes: {
    				entity: { typeName: "mscrm.team", structuralProperty: 5 },
    				Members: { typeName: "Collection(mscrm.systemuser)", structuralProperty: 4 }
    			},
    			operationType: 0, operationName: "AddMembersTeam"
    		};
    	}
    };
    
    Xrm.WebApi.execute(execute_AddMembersTeam_Request).then(
    	function success(response) {
    		if (response.ok) { console.log("Success"); }
    	}
    ).catch(function (error) {
    	console.log(error.message);
    });

  • Scott Parks Profile Picture
    20 on at

    Hi Andrew,

    I forgot to tell you that the code worked.

    Thank you so much,

    Scott

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

    Scott,

    If the code worked and you solved your initial request feel free to close the thread marking replies that helped as answers.

  • Scott Parks Profile Picture
    20 on at

    Sorry, where is the option to close the thread?

    Thanks,

    Scott

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

    It's located at the top of the reply under the message "Did this answer your question?".

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 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans