locked
Jscript in CRM 2011 to evaluate and concatenate information to create a unique policy number RRS feed

  • Question

  • I need to create a view-only non editable field for a policy number that is calculated/made up of the last 4 digits of the social security number + last 2 of the birth year + 2 digits of the birth month + 2 digits of the birth day. I know there needs to be a trim function? plus a concatenation. Can someone please provide an example of how this would be done in jscript in CRM?

    Monday, July 15, 2013 1:34 PM

All replies

  • Hi,
    assuming the SSN and the birth date are two fields inside the form, you can use the following code:

    var ssn = Xrm.Page.getAttribute("new_ssn").getValue();
    var birthdate = Xrm.Page.getAttribute("new_birthdate").getValue();
    
    var last4digits = ssn.slice(-4);
    var year2digits = (birthdate.getFullYear()+'').slice(-2);
    var month2digits = (birthdate.getMonth()+1)+'';
    var day2digits = birthdate.getDate()+'';
    
    if (month2digits.length == 1) month2digits = '0' + month2digits;
    if (day2digits.length == 1) day2digits = '0' + day2digits;
    
    var policynumber = last4digits + year2digits + month2digits + day2digits;
    Xrm.Page.getAttribute("new_policynumber").setValue(policynumber);


    My blog: www.crmanswers.net

    Monday, July 15, 2013 1:45 PM
  • Hi,

    below is the example for getting last 4 digits from a number. In this way you can do for all your numbers and finally concatenate all those.

    var id = "23456578"; var lastFour = id.substr(id.length - 4); // = "6578"

    OR

    id.slice(-4); 

    Thanks,

    sravan J

    Monday, July 15, 2013 1:49 PM