實現(xiàn)步驟:
創(chuàng)新互聯(lián)建站主營渝北網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,渝北h5小程序制作搭建,渝北網(wǎng)站營銷推廣歡迎渝北等地區(qū)企業(yè)咨詢
創(chuàng)建自定義workflow activity ,實現(xiàn)對CRM數(shù)據(jù)更新。
創(chuàng)建自定義workflow,實現(xiàn)整個流程。
集成自定義workflow到CRM.
?
創(chuàng)建自定義workflow activity
啟動 Microsoft Visual Studio 2010。
在"文件"菜單上,單擊"新建",然后單擊"項目"。
在"新建項目"對話框的"已安裝的模板"窗格中,選擇"Visual C#"下的"工作流",然后選擇"活動庫"。
指定解決方案的名稱和位置,然后單擊"確定"。
導(dǎo)航到"項目"菜單并選擇"屬性"。在"應(yīng)用程序"選項卡上,指定".NET Framework 4"作為目標(biāo)框架。
添加對 Microsoft.Xrm.Sdk.dll 和 Microsoft.Xrm.Workflow.dll 程序集的引用。
刪除項目中的 Activity1.xaml 文件。
將類文件 (.cs) 添加到項目中。在解決方案資源管理器中,右鍵單擊項目,選擇"添加",然后單擊"類"。在"添加新項"對話框中,鍵入類的名稱,然后單擊"添加"。
打開類文件,然后添加以下 using 指令:
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
使該類繼承自 CodeActivity 類:
public class SampleCustomActivity : CodeActivity
通過添加Execute方法為類添加功能:
protected override void Execute(CodeActivityContext context)
{
//Activity code
Update Data here
}
編譯項目以創(chuàng)建程序集 (.dll)。
?
?
創(chuàng)建自定義workflow
若要使用在 Microsoft Dynamics CRM 之外創(chuàng)建或修改的 XAML 工作流,請確保:
您的用戶帳戶在 Microsoft Dynamics CRM 中具有 Deployment Administrator權(quán)限。
在 Microsoft Dynamics CRM 服務(wù)器上啟用了聲明性工作流。 PowerShell($setting.AllowDeclarativeWorkflows="True")
創(chuàng)建工作流項目
在 Microsoft Visual Studio 中的"文件"菜單上,選擇"新建",然后單擊"項目"。
在"已安裝模板"下展開"Visual C#",然后單擊"工作流"。
單擊"活動庫",選擇".NET Framework 4",為項目指定名稱和位置,然后單擊"確定"。
在"解決方案資源管理器"中,右鍵單擊"活動庫",然后單擊"添加引用"。
單擊"瀏覽",并找到 Microsoft.Xrm.Sdk.dll 和 Microsoft.Xrm.Sdk.Workflow.dll文件。選擇這些文件并將其添加到項目。
進(jìn)行工作流的定制。
集成自定義workflow到CRM.
使用插件注冊工具來注冊自定義工作流活動程序集到CRM。
構(gòu)建 Plug-in Registration 工具。您可在SDK\Tools\PluginRegistration 文件夾中找到該工具的源代碼。若要構(gòu)建和使用插件注冊工具,您必須首先安裝 Windows Identity Foundation。
用戶帳戶必須具有系統(tǒng)定制員或系統(tǒng)管理員角色。
導(dǎo)入自定義的workflow
%TrainingKit%\Labs\WorkflowVS2010\Sources\Assets\WorkflowXamlTool.
打開 WorkflowXamlTool.sln, 修改workflow name and primaryentity ,執(zhí)行solution.
?
var newWF = new Entity("workflow");
newWF.Attributes.Add("name", "On test 10311");
newWF.Attributes.Add("type", new OptionSetValue(1));
newWF.Attributes.Add("scope", new OptionSetValue(4));
newWF.Attributes.Add("category", new OptionSetValue(0));
newWF.Attributes.Add("primaryentity", "abc_dummy");
newWF.Attributes.Add("xaml", content2);
newWF.Attributes.Add("ondemand", true);
?
try
{
_serviceProxy.Create(newWF);
?
MessageBox.Show("Workflow successfully imported.", "Import",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (FaultException ex)
{
}
選擇自定義xaml 文件,導(dǎo)入。
1.給類型賦值不同
CRM4 plugin給lookup賦值為空 :
Lookup lookupnull = new Lookup();
lookupnull.IsNull = true;
lookupnull.IsNullSpecified = true;
entity.Properties["new_storeroom_areaid"] = lookupnull;
CRM2011 給 EntityReference 賦值為空:
entity["new_storeroom_areaid"] = null;
2.單表查詢,返回Entity
CRM4.0 :
private DynamicEntity GetNewPrInfo(Guid NewPrID)//根據(jù)GUID查詢某字段
{
ColumnSet colSet = new ColumnSet(NewPrInfo.EntityName);
colSet.AddColumn(NewPrInfo.AttributeName_Assigner);
colSet.AddColumn(NewPrInfo.AttributeName_AssignNode);
TargetRetrieveDynamic target = new TargetRetrieveDynamic();
target.EntityId = NewPrID;
target.EntityName = NewPrInfo.EntityName;
RetrieveRequest request = new RetrieveRequest();
request.ColumnSet = colSet;
request.ReturnDynamicEntities = true;
request.Target = target;
RetrieveResponse response = (RetrieveResponse)this.crmService.Execute(request);
DynamicEntity PromotionPe = (DynamicEntity)response.BusinessEntity;
return PromotionPe;
}
CRM2011:
Entity accEntity = service.Retrieve(“new_test”, new_testid, new ColumnSet("字段1", "字段2"));//根據(jù)GUID,查詢實體new_test的字段1和字段2的值。
Entity accEntity = service.Retrieve(entityName, entityId, new ColumnSet(true));//根據(jù)GUID,查詢實體new_test的所有字段。
3.初始化CRM組織服務(wù)
CRM4:
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "";servername:port/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
CRM2011:
IFD 的服務(wù)前面的段必須是https,不分內(nèi)部和外部。
Uri orgServiceUri = new Uri("");
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = CRMUserName;
credentials.UserName.Password = CRMUserPassword;
OrganizationServiceProxy crmServiceProxy = new OrganizationServiceProxy(orgServiceUri, null, credentials, null);
crmService = (IOrganizationService)crmServiceProxy;
2. on-premise 內(nèi)部部署(AD認(rèn)證),,初始化WebService時的方式如下:
服務(wù)前面的段可以是https,也是可以http
如果沒有路由映射 外網(wǎng)是訪問不了 只能內(nèi)網(wǎng)訪問
Uri organizationUri = new Uri("");
IServiceConfigurationIOrganizationService orgConfigInfo = ServiceConfigurationFactory.CreateConfigurationIOrganizationService(organizationUri);
var Orgcreds = new ClientCredentials();
Orgcreds.Windows.ClientCredential = new System.Net.NetworkCredential("administrator", "admiN123", "DynamicCRM.com");
OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(orgConfigInfo, Orgcreds);
return (IOrganizationService)_serviceproxy;
這樣子也可以:
Uri orgServiceUri = new Uri(Config.CrmWebServiceUrl);
var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential(Config.CrmServerAccount, Config.CrmServerPSW, Config.CrmServerDomain);
OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(orgServiceUri, null, credentials, null);
return (IOrganizationService)_serviceproxy;
4.返回多個實體
CRM4:
// Create a column set holding the names of the columns to be retrieved.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {"name", "accountid"};
// Create the query object.
QueryByAttribute query = new QueryByAttribute();
query.ColumnSet = cols;
query.EntityName = EntityName.account.ToString();
// The query will retrieve all accounts whose address1_city is Sammamish.
query.Attributes = new string [] {"address1_city"};
query.Values = new string [] {"Sammamish"};
// Execute the retrieval.
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
CRM2011:
方法一:
string fetchxml = @"fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'
entity name='new_po_exp_detail'
attribute name='new_exp_amount' alias='new_exp_amount_sum' aggregate='sum' /
attribute name='new_submit_amout' alias='new_submit_amout_sum' aggregate='sum' /
attribute name='new_expense_category' alias='new_expense_category' groupby='true' /
filter type='and'
condition attribute='statecode' operator='eq' value='0' /
/filter
link-entity name='new_po' from='new_poid' to='new_po_exp_detail' alias='ab'
filter type='and'
condition attribute='statecode' operator='eq' value='0' /
condition attribute='new_po_status' operator='in'
value5/value
value7/value
/condition
condition attribute='new_promotion_pe' operator='eq' value='" + new_promotion_peId + @"' /
/filter
/link-entity
/entity
/fetch";
EntityCollection entitycols = service.RetrieveMultiple(new FetchExpression(fetchxml));
方法二:
QueryByAttribute query = new QueryByAttribute("new_categorytate");
query.ColumnSet = new ColumnSet("new_categorytateid");
query.AddAttributeValue("statecode", 0);
query.AddAttributeValue("new_sn", new_sn);//產(chǎn)品品類編號
EntityCollection encols = service.RetrieveMultiple(query);
新建asp.net web項目
編寫代碼
驗證服務(wù)
生成項目,并將相關(guān)文件拷貝到CRM的指定路徑
一.新建項目
右鍵點(diǎn)擊資源管理器項目,并添加一個web服務(wù),此處名稱為:MSCRMWebServiceDemo
引用相關(guān)的DLL文件
二.編寫代碼
[csharp] view plaincopy
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Description;
using System.Web;
using System.Web.Services;
namespace MSCRMWebServiceDemo
{
/// summary
/// MyMSCRMWebService 的摘要說明
/// /summary
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請取消注釋以下行。
// [System.Web.Script.Services.ScriptService]
public class MyMSCRMWebService : System.Web.Services.WebService
{
static private IOrganizationService GetOrganisationService()
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential("crmadmin", "password01!", "test");
OrganizationServiceProxy proxy = new OrganizationServiceProxy(new Uri(""), null, credentials, null);
return proxy as IOrganizationService;
}
[WebMethod]
public string HelloWorld()
{
IOrganizationService service = GetOrganisationService();
//用FETCHXML的方式獲取會員數(shù)據(jù)
string fetch2 = @"
fetch mapping='logical'
entity name='account'
attribute name='name' /
attribute name='address1_city' /
attribute name='primarycontactid' /
attribute name='telephone1' /
attribute name='accountid' /
order attribute='name' descending='false' /
link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='accountprimarycontactidcontactcontactid'
attribute name='emailaddress1' /
/link-entity
/entity
/fetch";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetch2));
String name = "";
foreach (var c in result.Entities)
{
name += c.Attributes["name"];
}
return name;
}
}
}
三.點(diǎn)擊VS的運(yùn)行按鈕,測試服務(wù)
四.部署相關(guān)項目至CRM指定路徑
拷貝MSCRMWebServiceDemo.dll至CRM的以下路徑:
X:\Program Files\Microsoft Dynamics CRM\CRMWeb\bin
拷貝MyMSCRMWebService.asmx至CRM的以下路徑:
C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ISV
最后驗證一下webservice,打開地址,出現(xiàn)以下界面則部署成功
微軟Dynamics CRM無縫集成Office 365、Power BI等生產(chǎn)力工具強(qiáng)大友好,xRM架構(gòu)開放靈活,私有云、公有云和混合云自由選擇。微軟Dynamics CRM解決方案與您一同見證企業(yè)崛起!微軟Dynamics CRM無縫集成Office 365、Power BI等生產(chǎn)力工具強(qiáng)大友好,xRM架構(gòu)開放靈活,私有云、公有云和混合云自由選擇。微軟Dynamics CRM解決方案與您一同見證企業(yè)崛起!
網(wǎng)頁標(biāo)題:dynamicsxrm的簡單介紹
本文路徑:http://vcdvsql.cn/article34/doiscpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、App開發(fā)、網(wǎng)頁設(shè)計公司、全網(wǎng)營銷推廣、營銷型網(wǎng)站建設(shè)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)