12 Mart 2013 Salı

CRM 2011 JAVASCRIPT - TAB ve SECTION GİZLEME


Asagıda kullanıcıya gore herhangi bir tab ve o tabın ıcındekı hangı sectionları kullanıcının goremeyecegı script yazılmıstır.

Javascript Code

function KullaniciActiviteGirAccount(kullanici) {
    var kullanici = Xrm.Page.context.getUserId();
    if (kullanici != null && kullanici != undefined) {
        kullanici = kullanici.replace('{', '').replace('}', '');
        if (kullanici == "2154F6F1-DC54-E211-AAA4-00155D005200" || kullanici == "CFB253CC-DC54-E211-AAA4-00155D005200") {
            setVisibleTabSectionAccount("notes and activities", "accountactivitiesgrid", true);
        }
        else {
            setVisibleTabSectionAccount("notes and activities", "accountactivitiesgrid", false);
        }
    }
}


function setVisibleTabSectionAccount(tabname, sectionname, show) {
    var tab = Xrm.Page.ui.tabs.get(tabname);
    if (tab != null && tab != undefined) {
        if (sectionname == null || sectionname =="")
            tab.setVisible(show);
        else {
            var section = tab.sections.get(sectionname);
            if (section != null && section !=undefined) {
                section.setVisible(show);
                if (show)
                    tab.setVisible(show);
            }
        }
    }
}

11 Mart 2013 Pazartesi

CRM 2011 - PLUGIN MESAJ


Örnegin,teklif yaratırken hem teklif üzerinden hem firsat üzerinden teklif yaratırız.Teklif create için plugin yazdıysak bunun hangi create anında calısmasını plugin registor tool üzerinden vermemız gerekır.

İlk Senaryo : Sales->Quotes->New (Teklif üzerinden teklif yaratma)


PLugin  Code

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using Microsoft.Crm.Sdk.Metadata;
using System.Web.Services;
using Microsoft.Win32;

namespace TestQuotePlugin
{
    public class QuotePlugin : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            ICrmService crmService = (ICrmService)context.CreateCrmService(true);
     IMetadataService metaData = context.CreateMetadataService(true);
     lead ld = new lead();
            ld.subject = "Test Subject";
            ld.firstname = "Test FirstName";
            ld.lastname = "Test LastName";
            ld.companyname = "Test Company";
            crmService.Create(ld);
        }    
    }
}


Bu sekılde olustugunda fırsat üzerinden teklif yaratılınca plugin calısmayacaktır.

İkinci senaryo : Sales->Opportunity->(Open Opportunity)->Quotes->New Quote

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using Microsoft.Crm.Sdk.Metadata;
using System.Web.Services;
using Microsoft.Win32;

namespace TestQuotePlugin
{
    public class QuotePlugin : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            CrmService crmService = CreateCrmService(context);    
     lead ld = new lead();
            ld.subject = "Test Subject";
            ld.firstname = "Test FirstName";
            ld.lastname = "Test LastName";
            ld.companyname = "Test Company";
            crmService.Create(ld);
        }   

        private static CrmService CreateCrmService(IPluginExecutionContextcontext)
        {
            CrmAuthenticationToken token = new CrmAuthenticationToken();
            token.AuthenticationType = AuthenticationType.AD;
            token.OrganizationName = context.OrganizationName;

            CrmService crmService = new CrmService();
            crmService.UseDefaultCredentials = true;
            crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";
            crmService.CrmAuthenticationTokenValue = token;
            return crmService;
        }   
    }
}






8 Mart 2013 Cuma

CRM 2011 -CUSTOMIZATIONS.xml KULANARAK RİBBONA BUTON EKLEME, CUSTOMRULE ve BUTONA TIKLAYINCA CUSTOM ASPX AÇMA


Solution ı kullanarak hangi entity e buton ekleyeceksek o entity nin customizations.xml i indirilir.Daha sonra <RibbonDiffXml> tagını asagıdakı gıbı degıstırınız.WebResource da List_main_library.js adlı javascript library si olusturdum ve içerigine kullanacagım fonksiyonlarımı yazdım.(Javascript kodları sayfanın altındadır.)


<RibbonDiffXml>
        <CustomActions>
          <CustomAction Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.CustomAction" Location="Mscrm.Form.list.MainTab.Actions.Controls._children" Sequence="41">
            <CommandUIDefinition>
              <Button Id="Okalip.Form.list.MainTab.Actions.CreateListonEuroMessage" Command="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Command" Sequence="29" ToolTipTitle="$LocLabels:Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.LabelText" LabelText="$LocLabels:Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.LabelText" ToolTipDescription="$LocLabels:Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Description" TemplateAlias="o1" Image16by16="/_imgs/ribbon/convert_16.png" Image32by32="/_imgs/ribbon/convert_32.png" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinitionId="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Command">
            <EnableRules>
              <EnableRule Id="Okalip.Form.list.MainTab.Actions.CreateListonEuroMessage.Command.EnableRule.AGC" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Command.DisplayRule.FormStateRule" />
            </DisplayRules>
            <Actions>
             <JavaScriptFunction FunctionName="CreateListonEuroMessageOnClick" Library="$webresource:List_main_library.js" />
              <!--<Url Address ="http://www.google.com" />-->/*direkt url verme*/
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules>
            <DisplayRule Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Command.DisplayRule.FormStateRule">
              <FormStateRule State="Create" Default="true" InvertResult="true" />
            </DisplayRule>
          </DisplayRules>
          <EnableRules>
            <EnableRule Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Command.EnableRule.AGC">
              <CustomRule FunctionName="CreateListonEuroMessageEnable" Library="$webresource:List_main_library.js" Default="false" InvertResult="true" />
            </EnableRule>
          </EnableRules>
        </RuleDefinitions>
        <LocLabels>
          <LocLabel Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.Description">
            <Titles>
              <Title languagecode="1033" description="CreateListonEuroMessage Description" />
              <Title languagecode="1055" description="Euromessage arayüzünde liste olustur." />
            </Titles>
          </LocLabel>
          <LocLabel Id="Gokhan.Form.list.MainTab.Actions.CreateListonEuroMessage.LabelText">
            <Titles>
              <Title languagecode="1033" description="Create List on EuroMessage" />
              <Title languagecode="1055" description="Liste olustur" />
            </Titles>
          </LocLabel>
        </LocLabels>
      </RibbonDiffXml>


List_main_library.js javascript kodları

function CreateListonEuroMessageEnable() {
    return true;
/*Geriye donus degeri True gonderılırse buton disable,false gonderılırse buton enable olacaktır.Burada işlemlerinizi yapıp ,işleme gore true,false geriye deger gonderılır*/
}

/*Gokhan Mentese*/
function CreateListonEuroMessageOnClick() {
    var _userId = Xrm.Page.context.getUserId();
    var entityid = Xrm.Page.data.entity.getId();
    var orgname = Xrm.Page.context.getOrgUniqueName();

    if (_userId != null && entityid != null && orgname != null) {
        var url = null;
        if (orgname != null) {
            url = "http://localhost:8083/OnlyCreateList.aspx?userid=" + _userId + "&entityid=" + entityid + "&orgname=" + orgname;
/*Iss üzerinde calısan site deki OnlyCreateList.aspx sayfamı cagırıyorum.Beraberınde query string de yolluyorum */
        }
        if (url != null) {
            var features = 'height=300,width=450,left=300,top=150,resizable=yes,titlebar=no,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no, status=no';
            window.open(url, 'GokhanMentese', features);
        }
    }
}