Search code examples
javascriptdynamics-crm-2011dynamics-crmguid

Compare mscrm GUIDs in js


Is there some better/official way, how to compare CRM 2011 GUIDs in JavaScript

2e9565c4-fc5b-e211-993c-000c29208ee5=={2E9565C4-FC5B-E211-993C-000C29208EE5}

without using .replace() and .toLowerCase()?

First one is got thru XMLHttpRequest/JSON:

JSON.parse(r.responseText).d.results[0].id 

Second one is got from form:

Xrm.Page.getAttribute("field").getValue()[0].id

Solution

  • There is no official way to compare GUIDs in JavaScript because there is no primitive GUID type. Thus you should treat GUIDs as strings.

    If you must not use replace() and toLowerCase() you can use a regular expression:

    // "i" is for ignore case
    var regExp = new RegExp("2e9565c4-fc5b-e211-993c-000c29208ee5", "i"); 
    
    alert(regExp.test("{2E9565C4-FC5B-E211-993C-000C29208EE5}"));
    

    It would probably be slower than replace/toLowerCase().