Skip to main content
CRM

MSCRM – Use JavaScript to Show/Hide Sensitive Data

By October 25, 2016No Comments

In this post, I’ll show you how to use JavaScript to show fields for a set amount of time then hide them again. My scenario involves a client that needs sensitive customer data stored in their CRM but it doesn’t need to be visible on the screen at all times. I created a checkbox and some simple JavaScript so that they can choose when to see the data. The data will automatically switch back to hidden again after 5 seconds. The purpose of this is to ensure that the data isn’t inadvertently left visible on the screen. In most cases, they only need to use the data for identification purposes so 5 seconds is long enough.

First, create a checkbox (data type of Two Options) for your form and name it something like “Show Sensitive Data.” Add the new field to your form near the field containing the sensitive data and make sure the default visibility setting for your hidden field is unchecked.

visibility

Create and/or add a JavaScript library to your form and paste the following functions into it. Anything in quotations needs to be updated based on the names of your fields. For example, “new_showhidesensitivedata” is the schema name for my checkbox and “new_sensitive” is the schema name for the field containing sensitive info.

//used with showSensData
function checkSensData() {
    var check = Xrm.Page.getAttribute(“new_showhidesensitivedata”).getValue();
    var option = Xrm.Page.data.entity.attributes.get(“new_showhidesensitivedata”);
    if (check) {
        option.setValue(false);
        Xrm.Page.getAttribute(“new_showhidesensitivedata”).fireOnChange();
    }
}

//show or hide sensitive data fields based on checkbox value. waits 5 secs before auto-hiding
function showSensData(){
    var check = Xrm.Page.getAttribute(“new_showhidesensitivedata”).getValue();
    var option = Xrm.Page.data.entity.attributes.get(“new_showhidesensitivedata”);
    var controlSens = Xrm.Page.getControl(“new_sensitive”);
    if(check){
        controlSens.setVisible(true);
        setTimeout(checkSensData, 5000);
    }
    else{
        controlSens.setVisible(false);
    }
}

The function “checkSensData” will only be called by the main function to uncheck the box automatically for us. The main function “showSensData” should be set up to trigger on change of the checkbox field. Register for next month’s Dynamics CRM webinar to see it in action!

trigger

 

Skip to content