在Azure环境里,Sharepoint 2013 实现从CRM(Dynamics)读取数据,编辑和新建。

上一篇       需要在SharePoint online 显示 CRM online的数据,并且有交互。需要开发是肯定的。由于我的本性能有限,

所以不太可能使用本机开发,使用虚拟机发现速度太慢,于是我选择了使用 Azure。结果顺利完成任务。所以继续分享。

当然你需要把Azure 开发的网站等内容 让外网访问的话,你要设置开放你的端口,让外界访问。单击下面的红色圈


在下面 单击Endpoints. 低栏有添加,添加开放端口。


下图单击对号完成。


完成开放设置后,写读取 编辑,新建代码。

读取数据使用,上篇做过简单说明,如下

编辑如下,工具是Gridview

一 读取和显示 上篇。

编辑 保存。

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Uri orgServiceUri = new Uri("https://xxxx.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");

        var clientCredentials = new ClientCredentials();
        clientCredentials.UserName.UserName = "jasondct@xxxxonmicrosoft.com";
        clientCredentials.UserName.Password = "xxxxxxxx";
        IOrganizationService orgService = new OrganizationServiceProxy(orgServiceUri, null, clientCredentials, null);
        //start insert Data
   

        string stitle =       ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string sIncidentId =  GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sdescription = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
       
        UpdateIncident(sIncidentId, stitle, 0, 0, 0, 0, sdescription, orgService);

        GridView1.EditIndex = -1;
        SDKCRM();   
    }

CRM 方法

    private void UpdateIncident(string sIncidentId, string stitle, int icasetypecode, int icustomersatisfactioncode, int iprioritycode,

                                int iseveritycode, string sdescription, IOrganizationService service)
    {

        Entity entIncident = new Entity("incident");

        entIncident.Id = Guid.Parse(sIncidentId);

        entIncident.Attributes["title"] = stitle;

        if (icasetypecode != 0)
        {

            entIncident.Attributes["casetypecode"] = new OptionSetValue(icasetypecode);

        }

        if (icustomersatisfactioncode != 0)
        {

            entIncident.Attributes["customersatisfactioncode"] = new OptionSetValue(icustomersatisfactioncode);

        }

        if (iprioritycode != 0)
        {

            entIncident.Attributes["prioritycode"] = new OptionSetValue(iprioritycode);

        }

        if (iseveritycode != 0)
        {

            entIncident.Attributes["severitycode"] = new OptionSetValue(iseveritycode);

        }

        entIncident.Attributes["description"] = sdescription;

        service.Update(entIncident);

    }

向CRM插入一条数据的方法。

    protected void butSave_Click(object sender, EventArgs e)
    {
        Uri orgServiceUri = new Uri("https://xxxx.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");

        var clientCredentials = new ClientCredentials();
        clientCredentials.UserName.UserName = "jasondct@xxxx.onmicrosoft.com";
        clientCredentials.UserName.Password = "xxxxxxxx";
        IOrganizationService orgService = new OrganizationServiceProxy(orgServiceUri, null, clientCredentials, null);


        string G =GetTdGuid;
        string stitle= txttitle.Text;
        string sresponsiblecontactid=txtcustomer.Text;
        string sdescription=txtDecription.Text;
      
        CreateIncident(stitle, G, 0, 0, 0, 0, sdescription, orgService);
        SDKCRM();
    }


 private void CreateIncident(string stitle, string sresponsiblecontactid, int icasetypecode, int icustomersatisfactioncode, int iprioritycode,

                                int iseveritycode, string sdescription, IOrganizationService service)
    {

        Entity entIncident = new Entity("incident");

        entIncident.Attributes["title"] = stitle;

        if (icasetypecode != 0)
        {

            entIncident.Attributes["casetypecode"] = new OptionSetValue(icasetypecode);

        }

        if (icustomersatisfactioncode != 0)
        {

            entIncident.Attributes["customersatisfactioncode"] = new OptionSetValue(icustomersatisfactioncode);

        }

        if (iprioritycode != 0)
        {

            entIncident.Attributes["prioritycode"] = new OptionSetValue(iprioritycode);

        }

        if (iseveritycode != 0)
        {

            entIncident.Attributes["severitycode"] = new OptionSetValue(iseveritycode);

        }

        entIncident.Attributes["description"] = sdescription;

        entIncident.Attributes["responsiblecontactid"] = new EntityReference("contact", Guid.Parse(sresponsiblecontactid));

        Entity entContact = service.Retrieve("contact", Guid.Parse(sresponsiblecontactid), new ColumnSet("parentcustomerid"));

        if (entContact.Attributes.Contains("parentcustomerid"))
        {

            entIncident.Attributes["customerid"] = entContact.Attributes["parentcustomerid"];

        }

        service.Create(entIncident);

    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值