CRM 2011 introduced a new page model for JScript and it has thrown some people for a bit of a loop because it is so different from the model in CRM 4.0. The SDK has a lot of examples, but they are often over-kill when you're just trying to figure things out.

As a simple example to get started, let's say that you just want to get the GUID from a lookup field on a form. First, create a web resource with the following JScript function and then call the web resource and the function from your form's OnLoad event.

In this example, we want to get the GUID from the Potential Customer lookup on an Opportunity (assuming it's already there - this code doesn't include any checks to see if it has been set yet):

function showGUID() {
var Customer = Xrm.Page.getAttribute('customerid').getValue();
var CustomerId = Customer[0].id;
alert(CustomerId);
}

The trick is the second variable. A lookup is actually an array. It contains three values: a name, an entity type, and the GUID (or id). If you wanted to know if the Potential Customer was set to an Account or Contact, you could change the second variable to Customer[0].entityType.