首页 / 后端开发 / 正文

CRM相关操作

2541 发布于: 2019-05-24 读完约需9分钟

1.前端界面获取当前CRM实体记录的Guid:

var currentEntityId = Xrm.Page.data.entity.getId();

2.前端界面获取当前CRM实体记录字段的值:

Xrm.Page.getAttribute("createdfromcode").getValue();//createdfromcode为字段的CRM名称

3.向市场营销活动中添加成员:

AddMemberListRequest addMemberListRequest = new AddMemberListRequest();

addMemberListRequest.EntityId = new Guid(leadDs.Tables[0].Rows[0]["LeadId"].ToString());(会员记录Guid)

addMemberListRequest.ListId = new Guid("C567D8F2-4865-E711-80CD-005056BB7917");(市场活动记录Guid)

          AddMemberListResponse addMemberListResponse = service.Execute(addMemberListRequest) as AddMemberListResponse;

4.向实体中添加记录:

IOrganizationService service = CrmOrganization.GetService();//连接CRM实体记录


ExecuteTransactionRequest requestForTran = new ExecuteTransactionRequest()

{

     Requests = new OrganizationRequestCollection()

};

Entity createLeadItems = new Entity("lead");//实体名


//姓----文本字段赋值

createLeadItems["LastName"] = lastname;

//销售组织----查找字段赋值:new_saleorgid-目标实体中该字段的CRM名字;new_saleorg-目标实体名;new_saleorgid-需要赋的值

createLeadItems["new_saleorgid"] = new EntityReference("new_saleorg", new Guid(new_saleorgid));

//类型----选项集赋值

createImportwork["new_object"] = new OptionSetValue(1030);

//源文件记录数----数字类型赋值

createImportwork["new_sourcenum"] = Convert.ToDecimal(ImportData.Rows.Count);

CreateRequest createLeadRequest = new CreateRequest { Target = createLeadItems };

requestForTran.Requests.Add(createLeadRequest);

ExecuteTransactionResponse responseForTran = (ExecuteTransactionResponse)service.Execute(requestForTran);

5.WEB工程调用控制台程序:

ProcessStartInfo start = new ProcessStartInfo();

//start.Arguments 后面为向控制台传递的参数,用空格隔开,控制台以 args[] 数组的形式接收                

start.Arguments = loyaltyproId + " " + UploadFileUrl + " " + new_importworkId + " " + TargetList + " " + listId;

start.FileName = "C:\\ConsoleProgram\\BulkImportProcess\\BulkImportProcess.exe";

//以下注释部分为需要回传参数时候使用

//start.UseShellExecute = false;

//start.RedirectStandardInput = true;

//start.RedirectStandardOutput = true;

//start.RedirectStandardError = true;

//start.CreateNoWindow = true;


Process process = Process.Start(start);

6.在服务器新建文件

//filepath:新建文件路径; fileData: DataTable类型,新建文件内容
FileStream filestream = new FileStream(filepath, FileMode.Create);

IWorkbook workbook = ExcelHelper.BuildWorkbook(fileData);

workbook.Write(filestream);

workbook.Close();




SELECT t3.Value, t4.Label
FROM EntityAsIfPublishedView t1 WITH (NOLOCK)
inner join AttributeAsIfPublishedView t2 WITH (NOLOCK) on t2.EntityId=t1.EntityId
inner join AttributePicklistValueAsIfPublishedView t3 WITH (NOLOCK) on t3.OptionSetId=t2.OptionSetId
inner join LocalizedLabelAsIfPublishedView t4 WITH (NOLOCK) on t4.ObjectId=t3.AttributePicklistValueId
WHERE t1.LogicalName ='new_shop' and t2.LogicalName='new_shoptype'

and t4.LanguageId=2052 and t4.ObjectColumnName='Description'

new_shop—实体名
new_shoptype—字段名

版权声明:本作品系原创,版权归码友网所有,如未经许可,禁止任何形式转载,违者必究。

上一篇: 推荐一些Windows系统中好用的免费(开源)/收费的终端管理工具(命令行工具)

下一篇: C#/.NET应用程序编程开发中LINQ查询如何实现一个集合的分页?

本文永久链接码友网 » CRM相关操作

分享扩散:

发表评论

登录用户才能发表评论, 请 登 录 或者 注册