Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Alert when User isn't supposed to see a record

Posted on by 777

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

  • Suggested answer
    Ben T Profile Picture
    Ben T 777 on at
    RE: Alert when User isn't supposed to see a record

    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? 

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Alert when User isn't supposed to see a record

    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:

    pravinpawarweb.wordpress.com/.../

  • rthompson Profile Picture
    rthompson 1,530 on at
    RE: Alert when User isn't supposed to see a record

    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/ 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans