locked
UUID/GUID Javascript

    Question

  • Is there a way to generate a GUID from Javascript?  I looked up at WRT reference, and I can't seem to find an obvious way to generate one.
    Friday, December 30, 2011 11:03 PM

Answers

All replies

  • No Sorry!

    I think Jquery may have some functions you can use though:
    http://www.bing.com/search?q=jquery+create+guid&go=&qs=n&sk=&form=QBLH

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, January 03, 2012 3:00 PM
    Moderator
  • I hit here looking for the same thing. there were many answers at stackoverflow to get a function in javascript. There are too many code snippets there, and one need to pick the right one for self.

    For javascript based windows store app - it may be simpler to add a winrt (say commonlib) and add a NewGuid method there. I have used this option.

    add a winrt component project say commonlib.

    namespace commonlib
    {
        public static class GuidUtils
        {
            public static System.Guid NewGuid()
            {
                return System.Guid.NewGuid();
            }
        }
    }


    -sushil

    Monday, March 25, 2013 7:44 AM
  • For WinJS you should not drag in the .net runtime but code the winrt component in C++.

    Something along the lines of

    #include <windows.h>
    
    namespace runtime { namespace guid {
      public ref class GUIDCreator sealed {
        public:
          static Platform::String^ CreateGuid() {
            GUID guid;
            HRESULT result = CoCreateGuid(guid);
            if FAILED(result) {
              throw ref new Platform::COMException(result);
            }
            WCHAR guidString[37];
            StringFromGUID2(&guid, guidString, 36);
            return ref new Platform::String(guidString);
          }
      };
    } }


    Tuesday, March 26, 2013 10:12 AM