We do not want to solve this problems using security roles and privileges for reasons beyond this post. Basically, we have custom look up field on a form to a user, and we need an alert box to pop up anytime a user that isn't the one in the lookup field opens the record. A simple javascript alert box would be fine. However, it would be great if we could have a custom alert box that said, "You are not authorized to view this record." And then had a "Continue" button to close the alert box and view the record, or a "Close" button that closed both the alert box and record.
Basically we are checking if the current user == custom_lookUp field vale. Can we javaScript to do this? Any easy out of the box ways?
*This post is locked for comments
Thank you, I did use the confirm dialog box. Here is the code I used:
function getCurrentUser(context) {
var userId = Xrm.Utility.getGlobalContext().userSettings.userId
console.log(userId);
//get lookup field user id
var lookUpField = context.getFormContext().getAttribute("new_lookUpField").getValue();
if (lookUpField != null) {
var lookUpFieldId = lookUpField[0].id;
}
//current user id != look up field id then display confirm box
if (lookUpFieldId != userId) {
var confirm = window.confirm("Continue");
if(confirm == false) {
window.history.back();
}
}
This solution works well. However, I would like to log whether the user presses "Continue" or "Cancel" on the window.confirm box. I would like to log it so that the activity can be seen in the global audit log. Is this possible?
I would suggest to use "Xrm.Navigation.openConfirmDialog" method of javascript on change of lookup field.
Make sure the names of buttons should be as follows:
confirmButtonLabel: “Continue”,
cancelButtonLabel: “Close”
on successful of confirmation it will close popup automatically where as if response get as close then close the record and redirect to entity view using js
Please refer below blog for reference:
Hi
Have you tried using Field Security. If you use field security it will show a lock on the form letting the user know only have read access.
Also to display a dialog add a javascript on change event on the field you are checking and do the following.
https://arunpotti.wordpress.com/tag/confirm-dialog-example-in-mscrm-2013/
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156