1
votes

First of all I am relatively new to 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. 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.

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. 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

1
I think the best you can do is read the Extension Chapter, you are talking about a lot of things, but they have to be taked one by one, one thing is client code (Javascripts, WebResources), another things are plug-ins, workflow, calls to the IOrganizationService via rest or soap. There is a lot of way to do what you need but I think you need to know what and why you are going to do that. - Sxntk
Great thanks for the advice. I thought that may have been the answer I got after posting this question. There is on specific task I would like to complete. However I will go away and read up more about the subject areas in question. - PhilC

1 Answers

0
votes

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

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 ;)