Softstuff Consulting
My occasional musings of a technical nature
  • Send us a message
  • About Softstuff Consulting
  • Privacy Policy
  • Main Website
JavaScript

Compare Guids in JavaScript

by Ian Blair February 23, 2019 No Comments

One of the problems with Guids in JavaScript is they can come in a few different formats depending on where you get them from, and as JavaScript doesn’t have a dedicated Guid data type like other languages such as C# it can make comparing them tricky. 

Examples of the same Guid are:

9D6FF5B4-C4C2-E511-8108-1458D043F638

{9D6FF5B4-C4C2-E511-8108-1458D043F638}

9d6ff5b4-c4c2-e511-8108-1458d043f638

{9d6ff5b4-c4c2-e511-8108-1458d043f638}

Some will have {} some will be in uppercase, and some in lower which makes doing a comparison between them tricky, especially as you are effectively doing a simple text comparison.

Using a little regex a simple function can be used.

The functions takes two Guids and performs a text comparison between them, but first it removes the {} and converts them to lower case before comparing.

 

function CompareGuid(guid1,guid2){
  If(guid1.replace(/[{}]/g,””).toLowerCase()==guid2.replace(/[{}]/g,””).toLowerCase())
     return true;
  }
  return false;
}

codejavascript

  • Previous Create an identical Queue in another CRM system6 years ago
  • Next Writing data to a Won Opportunity6 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to make your Powershell scripts more annoying
  • What motherboard is in my PC
  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365

Categories

  • Bootstrap
  • C#
  • CSS
  • Dot Net Core
  • Dynamics365
  • JavaScript
  • Powershell
  • T-SQL
  • Thoughts
  • VBScript
  • Visual Studio
  • Windows
  • Xamarin

Recent Comments

  • S0ftStuffB055 on Call a Dynamics365 workflow from JavaScript
  • Siva on Call a Dynamics365 workflow from JavaScript
  • TC Sharpe on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • BigOwl on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • CRMGod on Access a Dynamics365 embedded webresource

Archives

  • January 2021
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2025 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter