Hi,
I want to check whether a record exists in crm365 and based on that hide/show my Ribbon Workbench Button using javascript.
What would be the best way to achieve this?
Thanks,
Shreya k
*This post is locked for comments
Hi Shreya,
As per my information there is no any other way apart from synchronous mode.
Hi Pravin,
Thanks for your reply!
I have used the same code it does resolve the issue.
But, since the request is snychronous it is having an impact on the performance.
Regards,
Shreya K.
Hi Shreya,
Please refer below code:
var UserId = "3AB92M5-H357-E911-A817-00FD3A0B39K8"; // Your user id here
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/roles?fetchXml=%3Cfetch%20version%3D%221.0%22%20output-format%3D%22xml-platform%22%20mapping%3D%22logical%22%20distinct%3D%22true%22%3E%3Centity%20name%3D%22role%22%3E%3Cattribute%20name%3D%22name%22%20%2F%3E%3Cattribute%20name%3D%22businessunitid%22%20%2F%3E%3Cattribute%20name%3D%22roleid%22%20%2F%3E%3Corder%20attribute%3D%22name%22%20descending%3D%22false%22%20%2F%3E%3Clink-entity%20name%3D%22systemuserroles%22%20from%3D%22roleid%22%20to%3D%22roleid%22%20visible%3D%22false%22%20intersect%3D%22true%22%3E%3Clink-entity%20name%3D%22systemuser%22%20from%3D%22systemuserid%22%20to%3D%22systemuserid%22%20alias%3D%22ab%22%3E%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22systemuserid%22%20operator%3D%22eq%22%20uitype%3D%22systemuser%22%20value%3D%22%7BA" + + "%7D%22%20%2F%3E%3C%2Ffilter%3E%3C%2Flink-entity%3E%3C%2Flink-entity%3E%3C%2Fentity%3E%3C%2Ffetch%3E", false);
//Make sure that you have created request in synchronous mode
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
if(results.value.length > 0)
return true;
else
return false;
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
@Pravin Thanks for your reply. I want to return boolean value in order to enable my button based on the retrieved result. Currently, I am using async function to do the same due to which I am unable to return a value. Could you please share some suitable code to achieve this?
HI Shreya,
Please refer my below thread for your reference:
community.dynamics.com/.../942972
Here I would suggest you to retrieve user roles and hide buttons using enable rule
I will describe my query more clearly, I have 2 ribbon buttons Assign and Remove on the user form. If a user has been assigned a license, I want to hide the Assign button and show the Remove button and vice versa.
Thanks,
Shreya K
Hi Shreya,
As per my understanding , you need to hide the ribbon button for existing record.
Take this below as a reference.
Thanks,
Jagannath
Please check following community post community.dynamics.com/.../253850
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156