27 Nisan 2013 Cumartesi

CRM 2011 JAVASCRIPT-POPUP FORM ACMA (OPEN FORM POPUP)



function PopCase() {
    //Acılacak servis aktivitesinin degerlerini al
    var ExistingCase = Xrm.Page.data.entity.attributes.get("new_existingcase");
    if (ExistingCase.getValue() != null) {

        //Acılacak kayıdın adını ve guid id sini al
        var ExistingCaseGUID = ExistingCase.getValue()[0].id;
        var ExistingCaseName = ExistingCase.getValue()[0].name;

//Acılacak formda bellı parametreleri setle
var extraqs = "&title=New Case";
extraqs += "&customerid=" + CallerGUID;
extraqs += "&customeridname=" + CallerName;
extraqs += "&customeridtype=contact";

        //Acılacak pencere için feature olustur.
        var features = "location=no,menubar=no,status=no,toolbar=no";

        //Servis aktivitesi kayıdını ac
        window.open("/main.aspx?etn=incident&pagetype=entityrecord&id=" + encodeURIComponent(ExistingCaseGUID), "_blank", features, false);
    }
}

CRM 2011 JAVASCRIPT- CONTACT OLUSTURMA


function OnLoad() {
    if (Xrm.Page.ui.getFormType() == 1) {
    }
    else if (Xrm.Page.ui.getFormType() != 1) {
        DisableFields();
    }
}

function NewContact() {

    if (
            Xrm.Page.getAttribute("new_firstname").getValue() == null &&
            Xrm.Page.getAttribute("new_lastname").getValue() == null &&
            Xrm.Page.getAttribute("new_phonenumber").getValue() == null) {
        MakeFieldsNonMandatory();
    }
    else if (
                Xrm.Page.getAttribute("new_firstname").getValue() != null &&
                Xrm.Page.getAttribute("new_lastname").getValue() != null &&
                Xrm.Page.getAttribute("new_phonenumber").getValue() != null &&
                Xrm.Page.data.entity.attributes.get("customerid").getValue() == null) {
        CreateContact();
        Xrm.Page.getAttribute("new_phonenumber2").setValue(Xrm.Page.getAttribute("new_phonenumber").getValue());
        DisableFields();
    }
    else {
        MakeFieldsMandatory();
        //Xrm.Page.ui.controls.get("from").setVisible(false);
    }
}

function CreateContact() {
    // Get the CRM URL
    var serverUrl = Xrm.Page.context.getServerUrl();

    // Cater for URL differences between on premise and online
    if (serverUrl.match(/\/$/)) {
        serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    }

    // Specify the ODATA end point (this is the same for all CRM 2011 implementations)
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    // Specify the ODATA entity collection
    var ODATA_EntityCollection = "/ContactSet";

    // Define an object for the CRM record you want created
    var CRMObject = new Object();

    // Define attribute values for the CRM object
    CRMObject.FirstName = Xrm.Page.getAttribute("new_firstname").getValue();
    CRMObject.LastName = Xrm.Page.getAttribute("new_lastname").getValue();
    CRMObject.Telephone1 = Xrm.Page.getAttribute("new_phonenumber").getValue();

    //Parse the entity object into JSON
    var jsonEntity = window.JSON.stringify(CRMObject);

    //Asynchronous AJAX function to Create a CRM record using OData
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
        data: jsonEntity,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.    
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            //This function will trigger asynchronously if the Retrieve was successful
            //alert("ajax call successful");
            var NewCRMRecordCreated = data["d"];
            var FullName = Xrm.Page.getAttribute("new_firstname").getValue() + " " + Xrm.Page.getAttribute("new_lastname").getValue();
            SetLookupValue("customerid", NewCRMRecordCreated.ContactId, FullName, "contact");
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            //This function will trigger asynchronously if the Retrieve returned an error
            alert("ajax call failed");
        }
    });
}

function SetLookupValue(fieldName, id, name, entityType) {
    if (fieldName != null) {
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = id;
        lookupValue[0].name = name;
        lookupValue[0].entityType = entityType;
        Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
    }
}

function DisableFields() {
    Xrm.Page.ui.controls.get("new_firstname").setDisabled(true);
    Xrm.Page.ui.controls.get("new_lastname").setDisabled(true);
    Xrm.Page.ui.controls.get("new_phonenumber").setDisabled(true);
}

function MakeFieldsMandatory() {
    Xrm.Page.data.entity.attributes.get("new_firstname").setRequiredLevel("required");
    Xrm.Page.data.entity.attributes.get("new_lastname").setRequiredLevel("required");
    Xrm.Page.data.entity.attributes.get("new_phonenumber").setRequiredLevel("required");
}

function MakeFieldsNonMandatory() {
    Xrm.Page.data.entity.attributes.get("new_firstname").setRequiredLevel("none");
    Xrm.Page.data.entity.attributes.get("new_lastname").setRequiredLevel("none");
    Xrm.Page.data.entity.attributes.get("new_phonenumber").setRequiredLevel("none");
}



CRM 4 JAVASCRIPT - TELEFON ve EMAİL FORMATI


Telefon Formatı
function telFormat() {
    var oField = event.srcElement;
    if (crmForm.all.new_ulkeid.DataValue != null) {
        if (crmForm.all.new_ulkeid.DataValue[0].id == "{DFC9E4A3-6CED-DF11-81B6-005056A8444B}") {

            var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
            switch (sTmp.length) {

                case 10:
                    oField.DataValue = "+90 " + sTmp.substr(0, 3) + " " + sTmp.substr(3, 3) + " " + sTmp.substr(6, 4);
                    break;
                default:
                    alert('2122514500 þeklinde 10 haneli bir telefon numarasi giriniz.');
                    oField.DataValue = null;
                    break;
            }
        }
    }
    else {
        alert('Ülke Seçiniz');

        oField.DataValue = null;
    }
}

Not :DFC9E4A3-6CED-DF11-81B6-005056A8444B:Türkiye nin guid id sidir.

Email Formatı

function emailFormat() {

    var oField = event.srcElement;
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(oField.DataValue)) {
        return true;
    }
    alert("Geçerli bir e-posta adresi giriniz");
    oField.DataValue = null;
    return false;


}

CRM 2011 JAVASCRIPT - LOOKUP FİLTRELEME


        var eventid = Xrm.Page.getAttribute("tmp_eventtype").getValue();
        var eventname = Xrm.Page.getAttribute("tmp_eventtype").getText();
        //View için  random bir guid id tanımla
        var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}";
        var entityName = "ite_project";

        // View e bir isim tanımla
        var viewDisplayName = "Gokhan Mentese-Lookup Filtreleme";

        /*Lookup da görülecekler için fetch sorgusu olustur.Burada donen entitylerin statecode  u aktif olmalı*/
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                     "<entity name='ite_project'>" +
                     "<attribute name='ite_projectid' />" +
                     "<attribute name='ite_projectname' />" +
                     "<order attribute='ite_projectname' descending='false' />" +
                     "<filter type='and'>" +
                     "<condition attribute='ite_projecttype' operator='eq' value='" + eventid + "' />" +
                     "<condition attribute='statecode' operator='eq' value='0' />" +
                     "</filter>" +
                     "</entity>" +
                     "</fetch>";

        // build Grid Layout
        var layoutXml = "<grid name='resultset' " +
                               "object='1' " +
                               "jump='ite_projectid' " +
                               "select='1' " +
                               "icon='1' " +
                               "preview='1'>" +
                           "<row name='result' " +
                                "id='ite_projectid'>" +
                             "<cell name='ite_projectname' " +
                                   "width='200' />" +
                           "</row>" +
                         "</grid>";

        // Lookup kontrolune kendi yaptıgımız view i ekleyelim
        Xrm.Page.getControl("ite_project").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Artık ite_project lookup ını tıkladıgımızda bizim sorgumuza göre kayıtlar gelecektir.

9 Nisan 2013 Salı

CRM 2011 -Ribona Grup Buton Ekleme (Adding a new Button Group to the CRM Ribbon)


<CustomActions>
  <CustomAction Id="Mscrm.Form.account.CustomGroup.CustomAction"
                Location="Mscrm.Form.account.MainTab.Groups._children"
                Sequence="110">
    <CommandUIDefinition>
      <Group Id="Mscrm.Form.account.CustomGroup.Group"
              Command="Mscrm.Form.account.CustomGroup.Command"
              Title="Group Button"
              Sequence="51"
              Template="Mscrm.Templates.Flexible2">
        <Controls Id="Mscrm.Form.account.CustomGroup.Controls">
          <Button Id="Mscrm.Form.account.CustomGroup.Button.Buton1"
                  Command="Mscrm.Form.account.CustomGroup.Button.Buton1.Command"
                  Sequence="10"
                  LabelText="Button 1"
                  ToolTipTitle="TipTitle"
                  ToolTipDescription="TipDescription"
                  TemplateAlias="o1"
                  Image16by16="/_imgs/ribbon/newchart16.png"
                  Image32by32="/_imgs/ribbon/newchart32.png"  />
          <Button Id="Mscrm.Form.account.CustomGroup.Button.Buton2"
                  Command="Mscrm.Form.account.CustomGroup.Button.Buton2.Command"
                  Sequence="20"
                  LabelText="Button 2"
                  ToolTipTitle="TipTitle"
                  ToolTipDescription="TipDescription"
                  TemplateAlias="o1"
                  Image16by16="/_imgs/ribbon/CustomEntity_16.png"
                  Image32by32="/_imgs/ribbon/CustomEntity_32.png"   />
        </Controls>
      </Group>
    </CommandUIDefinition>
  </CustomAction>
  <CustomAction Id="Mscrm.Form.account.CustomGroup.MaxSize.CustomAction"
                Location="Mscrm.Form.account.MainTab.Scaling._children"
                Sequence="120">
    <CommandUIDefinition>
      <MaxSize  Id="Mscrm.Form.account.CustomGroup.MaxSize"
                GroupId="Mscrm.Form.account.CustomGroup.Group"
                Sequence="21"
                Size="LargeLarge" />
    </CommandUIDefinition>
  </CustomAction>
  <CustomAction Id="Mscrm.Form.account.CustomGroup.Popup.CustomAction"
                Location="Mscrm.Form.account.MainTab.Scaling._children"
                Sequence="140">
    <CommandUIDefinition>
      <Scale    Id="Mscrm.Form.account.CustomGroup.Popup.1"
                GroupId="Mscrm.Form.account.CustomGroup.Group"
                Sequence="85"
                Size="Popup" />
    </CommandUIDefinition>
  </CustomAction>
</CustomActions>