locked
Creating an entity record with silverlight RRS feed

  • Question

  • Hi everyone,

    I posted a similar post earlier; but have decided to re-phrase the question in a way that I'm hoping is easier to answer.

    My issue is that I need to create opportunity records with Silverlight into CRM 2011.  I've been successful in creating a Contact but not in Opportunity.  Could anyone either explain to me what needs to be done to create an opportunity record, or how to do it?

    Thanks,

    Bmckie

    Tuesday, September 24, 2013 12:46 PM

All replies

  • I would suggest posting the relevant code and any errors you might be receiving.


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, September 24, 2013 1:14 PM
    Moderator
  •  private void save_Click(object sender, RoutedEventArgs e)
            {
               
                int num = 1;
    
                dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
    
    
                // Specify Last Name and First Name for the contact to be created
    
    
                var childrenStacks = sp1.GetVisualChildren().OfType<StackPanel>();
                int x = 0;
    
                    KeyValuePair<string, object> oppRev = new KeyValuePair<string, object>();
                    KeyValuePair<string, object> oppProd = new KeyValuePair<string, object>();
                    KeyValuePair<string, object> oppDate = new KeyValuePair<string, object>();
                    var childs = p.GetVisualChildren().OfType<Control>();
                    foreach (var c in childs)
                    {
                        
                        String text = c.Name.ToString().Substring(0, 3);
                        switch (text)
                        {
                            case "REV":
                                TextBox t = c as TextBox;
                                String textString = t.Text;
                                oppRev.Key = "estimatedvalue";
                                oppRev.Value = textString;
                                break;
                            case "PRD":
                                //ListBox lb = c as ListBox;
                                oppProd.Key = "new_secondaryproducttype";
                                oppProd.Value = "100000001";
                                break;
                            case "DTP":
                                DatePicker dp = c as DatePicker;
                                String date = dp.Text;
                                oppDate.Key = "estimatedclosedate";
                                oppDate.Value = date;
                                break;
                        }
                    }
                    // Get IOrganizationService instance
                    IOrganizationService myOrgService = SilverlightUtility.GetSoapService();
                    Entity myOpp = new Entity();
                    myOpp.LogicalName = "opporunity";
    
                    // Create the AttributeCollection
                    myOpp.Attributes = new AttributeCollection();
    
                    KeyValuePair<string, object> oppName = new KeyValuePair<string, object>();
                    KeyValuePair<string, object> oppCust = new KeyValuePair<string, object>();
    
                    var name = xrm.Page.data.entity.attributes.get("name").getValue();
                    String names = Convert.ToString(name);
                    names = names + i;
    
                    var Cust = xrm.Page.data.entity.attributes.get("customerid");
                    var lookupvalue = Cust.getValue();
    
                    Guid? accountId = lookupvalue != null ? Guid.Parse(lookupvalue[0].id) : Guid.Empty;
    
                    oppCust.Key = "customerid";
                    oppCust.Value = accountId;// new EntityReference("account", Cust);
                    oppName.Key = "name";
                    oppName.Value = "createMe";
                    num++;
                    
                    //adding of attributes to the opportunity
                    myOpp.Attributes.Add(oppName);
                    myOpp.Attributes.Add(oppCust);
                    myOpp.Attributes.Add(oppRev);
                    myOpp.Attributes.Add(oppProd);
                    myOpp.Attributes.Add(oppDate);
    
                    MessageBox.Show("after adds");
                    OrganizationRequest myOrgRequest = new OrganizationRequest();
                    myOrgRequest.RequestName = "Create";
     
    
                    // call the Create method
    example - silverlightutility.cs
                    myOrgService.BeginCreate(myOpp, myCreateHandler, myOrgService);
                    MessageBox.Show("after create");
            }
    The code i based this off of was from this blog
    Tuesday, September 24, 2013 1:18 PM
  • Also I'm relatively new to silverlight so I dont know how to add error handling in CRM to the silverlight page.
    Tuesday, September 24, 2013 1:19 PM