locked
Microsoft Dynamic CRM 4.0 RRS feed

  • Question

  • Hi,


    I am new in microsoft dynamics crm. I am using crm4.0. And making a simple application for understanding in asp.net.

    What i am doing is there is a custom entity in my crm. And in that i want to add some data into that custom entity's attributes.

    Partly i became successful to enter the data for simple text property.

    But in case of drop down selected value i have done lots of R&D but nothings helps.

    I have populated my dropdown by contact entity.

    Now what i want is there is a lookup field(Primary Contact) in my custom entity, i want to add that asp.net dropdown selected value(contact) to custom entity attribute lookup field. There are contacts loaded in dropdown,i want just add that selected value into crm as i had done for simple textbox through. This becomes headache for me now.


    Here is my logic...

    code for populate drop down of account entity.

    -------------------------------------------

    ColumnSet cols = new ColumnSet();
                cols.Attributes = new string[] { "name", "accountid" };

                QueryExpression query = new QueryExpression();
                query.EntityName = EntityName.account.ToString();
                query.ColumnSet = cols;

                BusinessEntityCollection accounts = service.RetrieveMultiple(query);

                for (int i = 0; i < accounts.BusinessEntities.Length; i++)
                {
                    account fgaccount = (account)accounts.BusinessEntities[i];
                    FgProjectList.Add(new ListItem(fgaccount.name.ToString(), fgaccount.accountid.Value.ToString()));
                    DdlCompany.Attributes.Add(fgaccount.name.ToString(), fgaccount.accountid.Value.ToString());
                }

                DdlCompany.DataSource = FgProjectList;
                DdlCompany.DataBind();

    =========================================

     CRM.CrmAuthenticationToken token = new CRM.CrmAuthenticationToken();
            token.AuthenticationType = 0;
            token.OrganizationName = "indcrm";

            CrmService service = new CrmService();
            service.Url = "http://192.168.100.197:5555/MSCrmServices/2007/CrmService.asmx";
            service.CrmAuthenticationTokenValue = token;
            service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

            StringProperty name = new StringProperty();
            name.Name = "new_name";
            name.Value = TxtFGProjectName.Text.ToString();

            //Lookup companyId = new Lookup();
            //companyId.Value = new Guid();
            //companyId.type = EntityName.systemuser.ToString();
            
            Lookup myLU=new Lookup();
            myLU.name="Milan Hingu";
            myLU.type="contact";
            myLU.Value=new Guid(DdlCompany.SelectedValue);

            LookupProperty myLUprop = new LookupProperty();
            myLUprop.Name = "new_companyid";
            myLUprop.Value = myLU;
            //LookupProperty companyId = new LookupProperty();
            //companyId.Name = "new_companyid";
            //companyId.Value = //new Lookup("new_fgproject", new Guid(DdlCompany.SelectedValue));


            //StringProperty companyId = new StringProperty();
            //companyId.Name = "new_companyid";
            //companyId.Value = new Guid(DdlCompany.SelectedValue); //new Lookup("new_fgproject", new Guid(DdlCompany.SelectedValue)); //DdlCompany.SelectedValue;

            DynamicEntity testFg = new DynamicEntity();
            testFg.Name = "new_fgproject";

            PropertyCollection properties = new PropertyCollection();
            properties.Add(name.Name, name);
            //properties.Add(companyId.name, companyId);

            testFg.Properties = new Property[] { name,myLUprop };

            TargetCreateDynamic targetCreate = new TargetCreateDynamic();
            targetCreate.Entity = testFg;

            CreateRequest create = new CreateRequest();
            create.Target = targetCreate;

            try
            {
                CreateResponse created = (CreateResponse)service.Execute(create);
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw new Exception(ex.Detail.InnerText);
            }

    ====================================================

    Please help !!

    Monday, April 2, 2012 11:00 AM

Answers

  • Hi,

    I have resolved the issue. Don't know the reason but i have removed following two lines and its getting account id in value attribute.

    Remove following two lines .....

    DdlCompany.DataSource = FgProjectList;
    DdlCompany.DataBind();


    Regards,

    Milan Hingu
    • Marked as answer by DynamicsCRM31 Tuesday, April 3, 2012 10:38 AM
    Tuesday, April 3, 2012 10:38 AM

All replies

  • Is there anyone who faced any problem like this..??

    How would i get dropdown selected value in my attribute list.... I just want to save that selected value to crm and want to make one entry in new_fgproject with contact entry.

    I have tried all... Nothings work. I am using web services.

    Monday, April 2, 2012 1:45 PM
  • Hi,

    I have resolved the issue. Don't know the reason but i have removed following two lines and its getting account id in value attribute.

    Remove following two lines .....

    DdlCompany.DataSource = FgProjectList;
    DdlCompany.DataBind();


    Regards,

    Milan Hingu
    • Marked as answer by DynamicsCRM31 Tuesday, April 3, 2012 10:38 AM
    Tuesday, April 3, 2012 10:38 AM