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

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

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

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


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

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

下图单击对号完成。

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

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

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

编辑如下,工具是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 = "[email protected]";
        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 = "[email protected]";
        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);

    }




你可能感兴趣的:(SharePoint,azure,Dynamics)