الجمعة، 1 مايو 2015

Open Entity Form (New/existing) using JavaScript

//Open a new contact record
Xrm.Utility.openEntityForm("contact");
//Open an existing contact record
Xrm.Utility.openEntityForm("contact","A85C0252-DF8B-E111-997C-00155D8A8410");
//Open a new contact record with a specific form and setting default values
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "New Contact";
parameters["emailaddress"] = "email@example.com";
//For lookup
parameters["customerid"] = "257b689C8B47-8B9D-E111-883B-1CC1DEEA2718";
parameters["customeridname"] = "Test Cust";

Xrm.Utility.openEntityForm("contact", null, parameters);
//Open a new contact record, move it to the top left corner of the screen, and set the size of the window
var newWindow = Xrm.Utility.openEntityForm("contact");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);

///*******************************************************
Opens an HTML web resource:

//**Open an HTML web resource named "new_webResource.htm":
Xrm.Utility.openWebResource("new_webResource.htm");



//**Open an HTML web resource including a single item of data for the data parameter
Xrm.Utility.openWebResource("new_webResource.htm","dataItemValue");



//**Open an HTML web resource passing multiple values through the data parameter
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters);

الأحد، 26 أبريل 2015

Open CRM Lookup window in a custom page

function OpenLookup() {
    var serverURL = "http://Server:5555/OrganizationName/_controls/lookup/lookupinfo.aspx?AllowFilterOff=1&DefaultType=2&DefaultViewId=%7b00000000-0000-0000-00AA-000010001004%7d&DisableQuickFind=0&DisableViewPicker=0&LookupStyle=single&ShowNewButton=1&ShowPropButton=1&browse=0&objecttypes=123";


    var lookUp = window.showModalDialog(serverURL, 'entity', "dialogwidth: 750px; dialogheight: 600px; resizable: yes");

    ///For get return values

    //var name = lookUp.items[0].name; var id = lookUp.items[0].id;
    if (lookUp != null) {
        var data = eval('(' + lookUp + ')');
        alert(data.items[0].name + ":" + data.items[0].id);
    }
}

الاثنين، 20 أبريل 2015

Dynamics CRM 2013:Get/Set Business Process stage field value.

Xrm.Page.getControl("header_process_fieldname").getAttribute().setValue(value);  //Set Value

Xrm.Page.getControl("header_process_fieldname").getAttribute().getValue();  //Get Value

 //****** get the Id of business process Satge*******************************
    var StageId = Xrm.Page.getAttribute("stageid").getValue();
    
    if (StageId == "7f5247fe-cfc3-42bc-aa77-b1d836d9b7c0") {
        var Control = Xrm.Page.getControl("header_process_fieldname").getAttribute();
//fire onChange event.
        Control.addOnChange(FunctionName);
    }

الخميس، 16 أبريل 2015

How to assign Equipment/Facility to existed resource group.


//********* Create New Equipment/Facility *******************************
        Entity Equipment = new Entity("equipment");
        Equipment["name"]="Test Equipment 1";
        Equipment["timezonecode"]=1;
        Equipment["businessunitid"] = new EntityReference("businessunit", new Guid("BusinessUnitId"));

        Guid EquipmentId = _Service.Create(Equipment);
        //************************** Retrieve the Resource group***************
        Entity ResourceGroup = _Service.Retrieve("constraintbasedgroup", new Guid("ResourceGroupId"), new ColumnSet(true));
        //********************* Get the constrains of Resource group***************
        System.Text.StringBuilder builder = new System.Text.StringBuilder(ResourceGroup["constraints"].ToString());
        //******* Assing the equipment to resouce group ***************
        builder.Replace("</Body>", " || resource[\"Id\"] ==" + EquipmentId.ToString("B") + " </Body>");

        ResourceGroup["constraints"] = builder.ToString();
        //**************************** Update Resource Group***************
        _Service.Update(ResourceGroup);

الأربعاء، 25 فبراير 2015