简体   繁体   English

Microsoft CRM Dynamics Online-如何检索活动列表并向其添加联系人

[英]Microsoft CRM Dynamics Online - How to retrieve a list of Campaigns and add a contact to it

First of all I am relatively new to Microsoft Dynamics CRM Online. 首先,我是Microsoft Dynamics CRM Online的新手。

My aim: I want to take a list of current active campaigns (in my case a list of events) from our CRM and list them within a drop down list on a booking form. 我的目标是:我想从CRM中获取当前活动的活动列表(在我的情况下是事件列表),并在预订表格的下拉列表中列出它们。 I would then like a person to fill out a form and select an event they would like to attend. 然后,我希望有人填写表格并选择他们想参加的活动。 After clicking submit a contact will be created in the CRM and the person will be added in the "Responses" section as attending. 单击提交后,将在CRM中创建一个联系人,此人将作为出席者添加到“响应”部分中。

What I have so far: 到目前为止,我有:

public void Run(String connectionString, String AddDetails)
    {
        try
        {
            // Establish a connection to the organization web service using CrmConnection.
            Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(connectionString);

            // Obtain an organization service proxy.
            // The using statement assures that the service proxy will be properly disposed.
            using (_orgService = new OrganizationService(connection))
            {
                // Instantiate an account object.
                Entity account = new Entity("contact");

                // Set the required attributes. For account, only the name is required. 
                // See the metadata to determine 
                // which attributes must be set for each entity.
                account["lastname"] = AddDetails;

                _orgService.Create(account);
            }
        }

                    // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
        catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
        {
            // You can handle an exception here or pass it back to the calling method.
            throw;
        }
    }

I can create contacts and retrieve the unique ID for this record. 我可以创建联系人并检索该记录的唯一ID。 This works perfectly. 这很完美。 I just want to retrieve a campaign and attach it to the event/campaign next. 我只想检索一个广告系列,然后将其附加到事件/活动中。

My problem: I can not seem to get a list of campaigns to added them to a web page and then attach this person to the campaign. 我的问题:我似乎无法获得一个广告系列列表,无法将它们添加到网页上,然后将该人附加到广告系列中。

I have read quite a few articles for creating quick campaigns which are confusing. 我已经阅读了很多有关创建快速广告系列的文章,这些文章令人困惑。 Is what I am trying to achieve out of the norm? 我要实现的目标超出规范了吗? or impossible? 还是不可能? could anyone provide me with some code to get me started in the right direction? 谁能为我提供一些代码,以使我朝正确的方向入门?

Thanks in advance 提前致谢

First you need to retrieve the Campaigns 首先,您需要检索广告系列

QueryExpression qe = new QueryExpression("campaign");
qe.ColumnSet = new ColumnSet(true); // this will retrieve all fields, you should only retrieve attribute you need ;)

EntityCollection collection = _orgService.RetrieveMultiple(qe);

Then you can loop over this collection to get the list you need. 然后,您可以遍历此集合以获取所需的列表。

And then after your users submits the custom form either webresource or some other app you will need to create Campaign Response in CRM 然后,在用户提交自定义表单(网络资源或其他应用程序)之后,您将需要在CRM中创建广告系列响应

var campaignResponse = new Entity("campaignresponse");
campaignResponse["regardingobjectid"] = new EntityReference("campaign", YOUR CAMPAIGN GUID);
campaignResponse["customer"] = new EntityReference("lead/account/contact", RECORDGUID);
_orgService.Create(campaignResponse);

This should get you on the right track ;) 这应该使您走上正确的路;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM