Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Creating Opportunity with Silverlight

$
0
0

Hey all,

I found this sample online of how to create a contact through silverlight; I've tried to adapt that to create an opportunity and have had no success.

Thisis the resource that I've used as my baseline(which did work for creating the contact).

Does anyone know what I'm doing wrong to have this create an opportunity?(since i'm receiving no error messages; and the code executes until the very end where I have a messagebox flag.)

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;
            foreach (var p in childrenStacks)
            {


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


                myOrgService.BeginCreate(myOpp, myCreateHandler, myOrgService);
                MessageBox.Show("after create");
            }
        }


Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>