检索记录的 Guid 并在 Dynamics CRM 中创建新记录
Retrieve the Guid of the record and creating new record in Dynamics CRM
我想在 CRM 中创建新的商机记录。机会记录将根据此条件创建。它会将 CRM 中的帐户与 pipedrive 中的组织进行比较。如果找到匹配的名称,那么它会直接创建机会,否则它会先创建帐户,然后再创建机会。
如何向商机中的查找字段“帐户”字段添加值?
下面是我写到现在的代码。
从 CRM 获取帐户记录:
public EntityCollection GetAccount()
{
QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("name", "accountid") };
EntityCollection accountname = this.crmService.RetrieveMultiple(query);
return accountname;
}
查询账户是否存在:
int accountCount = account.Entities.Count;
string[] name = new string[accountCount];
for (int i = 0; i < accountCount; i++)
{
name[i] = account.Entities[i].Attributes["name"].ToString();
if (name[i] == message.Current.org_name || name[i].Contains(message.Current.org_name))
{
this.counter++;
this.flag = 1;
continue;
}
}
if (this.counter == 1)
{
c.CreateOpportunity(message);
}
else if (this.counter > 1)
{
c.CreateAccount(message);
c.CreateOpportunity(message);
}
if (this.flag == 0)
{
c.CreateAccount(message);
c.CreateOpportunity(message);
}
创建商机记录:
public void CreateOpportunity(Message message)
{
Entity opportunity = new Entity("opportunity");
opportunity["name"] = message.Current.Title;
opportunity["estimatedvalue"] = message.Current.value;
this.crmService.Create(opportunity);
}
您必须在 CreateOpportunity
方法中使用如下所示:
opportunity["CustomerId"] = new EntityReference("account", accountId);
"CustomerId"是客户属性的逻辑名,"account"是账户实体的逻辑名,accountId
应该从创建的账户记录PK Guid或者实体集合中匹配的账户PK传递你有
Guid accountId = account.Entities[i].Id;
我想在 CRM 中创建新的商机记录。机会记录将根据此条件创建。它会将 CRM 中的帐户与 pipedrive 中的组织进行比较。如果找到匹配的名称,那么它会直接创建机会,否则它会先创建帐户,然后再创建机会。
如何向商机中的查找字段“帐户”字段添加值?
下面是我写到现在的代码。
从 CRM 获取帐户记录:
public EntityCollection GetAccount()
{
QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("name", "accountid") };
EntityCollection accountname = this.crmService.RetrieveMultiple(query);
return accountname;
}
查询账户是否存在:
int accountCount = account.Entities.Count;
string[] name = new string[accountCount];
for (int i = 0; i < accountCount; i++)
{
name[i] = account.Entities[i].Attributes["name"].ToString();
if (name[i] == message.Current.org_name || name[i].Contains(message.Current.org_name))
{
this.counter++;
this.flag = 1;
continue;
}
}
if (this.counter == 1)
{
c.CreateOpportunity(message);
}
else if (this.counter > 1)
{
c.CreateAccount(message);
c.CreateOpportunity(message);
}
if (this.flag == 0)
{
c.CreateAccount(message);
c.CreateOpportunity(message);
}
创建商机记录:
public void CreateOpportunity(Message message)
{
Entity opportunity = new Entity("opportunity");
opportunity["name"] = message.Current.Title;
opportunity["estimatedvalue"] = message.Current.value;
this.crmService.Create(opportunity);
}
您必须在 CreateOpportunity
方法中使用如下所示:
opportunity["CustomerId"] = new EntityReference("account", accountId);
"CustomerId"是客户属性的逻辑名,"account"是账户实体的逻辑名,accountId
应该从创建的账户记录PK Guid或者实体集合中匹配的账户PK传递你有
Guid accountId = account.Entities[i].Id;