Javascript for masking the field RRS feed

  • Question

  • Hi All,

    I am having a numeric field , I want to display only last four digits of the value.

    Please give me some code so that I can implement this.

    Thanks in advance

    Friday, May 30, 2014 8:57 AM

All replies

  • Hi,

    For security reasons you should use a plugin for that and change the field value in the retrieve and retrieve multiple action. Javascript will mask the field after loading the form. So it could be happen to see the value before the script will masked it. Also someone would be able to see the value through advanced find, webservice or other ways.

    But be careful to not save the masked value back to the data store when a user saves the form. This means you also have to register a plugin on the update action which decides if the value is the masked old one or a new value.


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    Friday, May 30, 2014 10:07 AM
  • Will you please provide me the code ...
    Friday, May 30, 2014 10:16 AM
  • Hi,

    Like Steve pointed out, it will be best to have it done by a Plugin instead of a JavaScript. You can register a Plugin on RetreiveMultiple message of the entity and mask the field value before it is displayed in CRM (advanced find, form, etc.).

    See here for a sample of masking data in Advanced Find : http://hachecrm2011.wordpress.com/2013/07/19/filtering-views-by-intercepting-retrieve-multiple-queries-with-a-plugin/

    Admin QuikView Solution for CRM 2013

    Friday, May 30, 2014 10:37 AM
  • Hi All,

    I need to implement it in javascript only . Please provide me any code that will help me in implementing this...

    Please find the description below:

    Add an additional field - Masked . This field should be displayed on the form and the visibility of the actual SSN field should be hidden.

    Add script to copy the SSN from the actual field to the masked field with the first 5 numbers replaced by X.

    On save, check if the value has been edited, then copy back to the main field.

    Monday, June 2, 2014 5:54 AM
  • Hi,

    I got what the description says. So this is what you do:

    1. Create a new field called "Masked SSN" (or something meaningful). Hide the actual SSN field from the form.

    2. On Page Load, check if "Masked SSN" is empty. If yes, copy the actual SSN field value and populate "Masked SSN" with first 5 numbers masked.

    3. On Page Save, check if the "Masked SSN" has been changed and copy back to the actual SSN field. (But what I don't understand here is, if someone sees a masked value, why would you allow him to update it?!?)

    Now the steps that I said above have a lot of things to consider. Whenever you copy from actual SSN to Masked SSN, the dirty flag in the form will be set and the user will get an "You have unsaved changes pending", etc. warning although they haven't changed a thing.

    Admin QuikView Solution for CRM 2013

    Monday, June 2, 2014 8:48 AM
  • we are hiding the actual ssn number field and showing only the masked ssn field on the form.

    how to check it on save ?

    any code related ?

    Monday, June 2, 2014 9:16 AM
  • Hi,

    Yes, as per your description that is how it's to be done.

    On Save, retrieve the value of "Actual SSN" and the value of "Masked SSN". If "Masked SSN" starts with XXXXX, that means it's not been changed; so no need to update "Actual SSN". If "Masked SSN" has been changed then it definitely wouldn't start with XXXX  (I guess I am right here??), so you can update the "Actual SSN" with the "Masked SSN".

    But I still don't get how a person can update SSN if he's not allowed to see the complete SSN at the first place.

    You can use the following commands to get or set field value:


    Admin QuikView Solution for CRM 2013

    Monday, June 2, 2014 9:57 AM