Friday, April 2, 2010

How to Create a New Guid with Javascript in Crm 4

Ever needed to create a new Guid on the fly with Javascript in Crm 4? There is actually a Javascript function that does just that.

  • Add a reference to CRMWeb\_static\Tools\FormEditor\Scripts\util.js (If necessary)
  • The function name is GetGuid()

The Code from util.js:

function GetGuid()
{
var sGuid = null;

try
{
var oCommand = new RemoteCommand("SystemCustomization", "GetGuid");
var oResult = oCommand.Execute();
if (oResult.Success)
{
sGuid = oResult.ReturnValue;
}
}
catch (e)
{
sGuid = null;
}

if (!sGuid)
{

openErrorDlg("0x80043b10");
}

return sGuid;
}




The function is used in Crm for creating a new import job and probably other things as well.  It is completely unsupported to use this function in your code, but imho better than using a third party JavaScript library to create the Guid.

No comments: