locked
Upgrading from CRM 4.O Javascript to CRM 2015 RRS feed

  • Question

  • We as a company are upgrading from CRM 4.0 to CRM 2015

    I am looking at a demo version of 2015 to get a feel for the setup

    I am trying to mirror an OnChange on a specific field from 4.0 to 2015

    Our code is -

    // Ensuring ISNI ID is formatted in 16 digits divided into 4 blocks 0000 0000 0125 9966

    var    isni              =  crmForm.all.cir_isni.DataValue;
    var regexFormat = /[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9,A-Z]{1}/;

    // Validate the format of the ISNI ID 

    if ( ! regexFormat.test(isni) ) {
    alert ("The ISNI ID number must match the following format: 0000 0000 0000 0000 or 0000 0000 0000 000X. ");
    }

    What would be the equivalent code in CRM 2015 to test on the demo

    Cheers in advance

    Tuesday, December 15, 2015 1:10 PM

All replies

  • CRM 2015 requires that your code is inside a javascript webresource and included in a function

    so let's say you added to the onchange event field the function checkISNI, the code will be

    function checkISNI() {
    var isni = Xrm.Page.getAttribute("cir_isni").getValue();
    if (isni != null) {
        var regexFormat = /[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9,A-Z]{1}/; // Validate the format of the ISNI ID
        if (!regexFormat.test(isni)) {
            alert ("The ISNI ID number must match the following format: 0000 0000 0000 0000 or 0000 0000 0000 000X. ");
        }
    }
    }



    My blog: www.crmanswers.net - CRM Theme Generator

    Tuesday, December 15, 2015 1:28 PM
  • Thanks for the reply.

    Incorporated the code into the OnChange and when I run the demo I am getting the message attached and the Error Details are as follows

    TypeError: Unable to get property 'getValue' of undefined or null reference
       at checkISNI 
       at eval code (eval code:1:1)
       at RunHandlerInternal 
       at RunHandlers 
       at ExecuteHandler 
       at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.$Aw_1 
       at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.executeHandler 
       at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.executeHandlerByDescriptor 
       at Anonymous function (
       at Anonymous function

    Any thoughts

    Thanks

    Tuesday, December 15, 2015 2:32 PM
  • hi,

    make sure that the field name is the correct one and that the field is added on the body of the form (not the header of the footer)


    My blog: www.crmanswers.net - CRM Theme Generator

    Tuesday, December 15, 2015 2:52 PM
  • function checkISNI() {
    if (Xrm.Page.getAttribute("cir_isni").getValue() != null){
    var isni = Xrm.Page.getAttribute("cir_isni").getValue();
    if (isni != null) {
        var regexFormat = /[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9,A-Z]{1}/; // Validate the format of the ISNI ID
        if (!regexFormat.test(isni)) {
            alert ("The ISNI ID number must match the following format: 0000 0000 0000 0000 or 0000 0000 0000 000X. ");
        }
    }
    }
    }
    Please check field name as advised by Andrii.

    Regards Faisal

    Friday, December 18, 2015 11:46 AM
  • Thanks very much both, I have now got this working with no errors

    Your assistance is much appreciated

    Friday, December 18, 2015 11:57 AM