Hi i have a requirement to check the logged in users Team on click of custom button and then change the status based on Team .
Kindly let me know if any pointers.
*This post is locked for comments
Hi i have a requirement to check the logged in users Team on click of custom button and then change the status based on Team .
Kindly let me know if any pointers.
*This post is locked for comments
Hi Sir,
There is error in response when i am using this code.
kindly guide.
Thanks Gautam ...
You can also try with single request -
function getLoginUserTeam() { var loggedInUserId = Xrm.Page.context.getUserId(); loggedInUserId = loggedInUserId.replace('{', '').replace('}', ''); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/teams$select=name&$expand=teammembership_association($filter=systemuserid eq "+loggedInUserId+")",true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); // I have not tried you can debug results part for (var i = 0; i < results.value.length; i++) { var teamname = results.value[i]["name"]; } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
Try with this -
function getLoginUserTeam() { var UserTeams = null; var loggedInUserId = Xrm.Page.context.getUserId(); loggedInUserId = loggedInUserId.replace('{', '').replace('}', ''); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/teammemberships?$select=teamid,teammembershipid&$filter=systemuserid eq "+loggedInUserId+"", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); for (var i = 0; i < results.value.length; i++) { var teamid = results.value[i]["teamid"]; var teammembershipid = results.value[i]["teammembershipid"]; var teamid = teamid.replace("{","").replace("}",""); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/teams("+teamid+")?$select=name,teamid", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); // You will get the team id and team name here var name = result["name"]; // Team Name var teamid = result["teamid"]; if(UserTeams == null) UserTeams = name; else UserTeams = UserTeams + "," + name; } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
Hi Divya ,
Check below old post here .
community.dynamics.com/.../218804
In addition I would suggest to download CRMRESTBuilder and prepare same code with web api instead of using organization service .
I haven't tried this before .it would be great if you post some sample code for the same
Hi DivyaBharathi,
It is actually not meant to be a link. I intended for it to be an example pseudocode for your JavaScript retrieve.
Hi Adrian thank you for your quick response
//retrieve team
customer.crm.dynamics.com/.../teams$select=name&$expand=teammembership_association($filter=systemuserid eq id);
this link is not accessible
Hi DivyaBharathi,
You can use JavaScript and the Ribbon Workbench for Dynamics 365 & Dynamics CRM to achieve this. This is a rough method for implementing this.
var id = Xrm.Page.context.getUserId(); //get ID //retrieve team customer.crm.dynamics.com/.../teams$select=name&$expand=teammembership_association($filter=systemuserid eq id); //change status based on team
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156