Monday 10 December 2012

Call custom activity form in CRM 2011 using javascript




  1. Add this javascript into your webresources.


function OpenForm(pids) {
    var serverUrl;
    var errorMessage = "Context is not available.";
    var context;
    if (typeof GetGlobalContext != "undefined") {
        context = GetGlobalContext();
    }
    else {
        if (typeof Xrm != "undefined") {


            context = Xrm.Page.context;
        }
        else {
            alert(errorMessage);
            return;
        }
    }
    var entityId = context.getQueryStringParameters().id


    var entityEtc = context.getQueryStringParameters().etc


    var serverUrl = context.getServerUrl();
    if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); }
    var recordUrl = serverUrl + "/userdefined/edit.aspx?";

//Here i used Fiddler tool to get TypeCode of my custom Activity.
    var params = "contactInfo=&etc=10004&pId="; // 10004 is type code of my custom activity.
    params += pids[0]; // Xrm.Page.data.entity.getId();
    params += "&pType=3"; // here type 3 is type code of Opportunity

    var URL = recordUrl + params;
    window.open(URL, "_blank", "width=900px,height=600px,resizable=1");
}


  1. Create a New button using visual ribbon editor.
  2. Click Action tab of Selected custom button.
  3. Then click Add link and then select JavaScriptFunction.
  4. There you have to give a function name and library path as follows:
  • Function Name: OpenForm
  • Library: $webresource:<created web resource name> //new_filename
  • Click Add link and the select CrmParameter.
  • Then select value: PrimaryItemIds


No comments:

Post a Comment