Showing posts with label Crm 4. Show all posts
Showing posts with label Crm 4. Show all posts

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.

Friday, October 24, 2008

Crm 4- Simple Function to Hide Attributes on A Form

Yesterday we had a project where a requirement was to 'filter' attributes on the form based on a picklist value. To accomplish this, a function to hide the attributes should be created. Opening the form source, we see that all form attributes have an ATTRIBUTE_NAME_d and an ATTRIBUTE_NAME_c id tag. One is for the label and the other is for the input (TextArea, Date field, etc). So the Javascript looks like this:

//Hides attributes on form
function HideAttributeOnForm(sAttributeName)
{
document.getElementById(sAttributeName + '_d').style.display = 'none';
document.getElementById(sAttributeName + '_c').style.display = 'none';
}

To use this, simply pass in the attribute name:

HideAttribute("YOUR_ATTRIBUTE_AS_A_STRING");