Sunday, November 6, 2011

CRM 2011 opening forms using URL

This is a very neat feature in CRM. Basically all entity forms can be accessed by using main.aspx and some pre definied query string parameters.
So for example your organisation is called constoso you can access any entity form url using the syntax
http://<yourserver>/contoso/main.aspx?etn=<yourEntity>&pagetype=entityrecord
note the two query string parameters etn and pagetype. These are pre defined parameters, this is not something I have come up with.
Here are the list of all possible parameters you can pass (from msdn)
  • etn -entity logical name
  • extraqs -optional parameters that can set values in a form.
  • pagetype - one of two values entityrecord or entitylist
  • id- optional for forms when you want to open a specific record
  • viewid - id for saved query or user query.
  • viewtype - 1039 for saved query and  4230 for user query.
For more detailed information refer to msdn
This is a very handy function. You can place button on forms and open up other forms or call it from your web resource such as asp.net or html page or silverlight or even add your custom buttons to the ribbon and open forms with prefilled values.

In my next post I will show you how to populate form values using query string parameters in the url.
The tricky one is populating the lookups.


Happy CRMing!

Thursday, November 3, 2011

Getting attibute value in CRM 2011


This is a generic function which will get you value of any attribute on the form.
Only two things you need to remember, for an optionset it will get the text for the selected option set and for a lookup it will get the first value in the lookup. So it will not get you values for thesystem lookups which can have multiple values.
function GetAttributeValue(attribute) {

    var attrib = Xrm.Page.data.entity.attributes.get(attribute);
    var type = attrib.getAttributeType(); 
    var value;
    switch (type) {
        case "boolean":
        case "decimal":
        case "double":
        case "integer":
        case "memo":
        case "string":
        case "money":
            value = attrib.getValue();
            break;
        case "optionset":
            value = attrib.getSelectionOption().text;
            break;
        case "datetime":
            value = attrib.getValue().toLocaleString();
            break;
        case "lookup":
            var lookupArray = attrib.getValue();
            value = lookupArray[0].name;
            break;
        default:
            value = null;
            break;
    }

    return value;


}
Happy CRMing!