locked
set value in querry expression of lookup property RRS feed

  • Question

  •                 crmservice.ColumnSet cols = new crmservice.ColumnSet(); //pag_clientid is lookuptype attribute
                    cols.Attributes = new String[] { "pag_clientid", "pag_name" };

                    crmservice.QueryByAttribute query = new crmservice.QueryByAttribute();
                    query.Attributes = new string[] { "pag_clientid" };
                    query.Values = new String[] { "IIT Delhi" };
                    query.EntityName = crmservice.EntityName.pag_contactperson.ToString();
                    query.ColumnSet = cols;

    This code is not working.

    Friday, July 24, 2009 4:45 AM

Answers

  • Nishant initial suggestion about using queryexpression is the correct one. But instead of querying the primary table which is the way to go only when you have a lookup id (guid) create a linked entity (join) with the child entity and construct the condition inside the linked entity.

     

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Friday, July 24, 2009 12:12 PM

All replies

  • Hi,

    Try with this

    QueryExpression query = new QueryExpression();
    
    				
    			query.EntityName = "entityName";
    
    			// Specify the columns to retrieve
    			ColumnSet columns = new ColumnSet();
    			columns.Attributes = new String[] {
    					"pag_clientid", "pag_name"};
    
    			query.ColumnSet = columns;
    
    			query.Criteria = new FilterExpression();
    			query.Criteria.FilterOperator = LogicalOperator.And;
    
    			// Create the accountid condition
    			ConditionExpression condition1 = new ConditionExpression();
    			condition1.AttributeName = ""pag_clientid"";
    			condition1.Operator = ConditionOperator.Equal;
    			condition1.Values = new Object[] {
    					new System.Guid("7d9c2a57-3057-dc11-bc50-00110a5cdc7f")};
    
    			query.Criteria.Conditions = new ConditionExpression[] {
    					condition1};
    
    			// Execute the query and return the result
    			crmService.RetrieveMultiple(query);

    In query.Values = new String[] { "IIT Delhi " };  i think you need to pass guid not the text.


    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
    Friday, July 24, 2009 4:52 AM
  • My problem is bit different.

    The value IIT Delhi is not constant. I am retriving the value as string through code and then I am trying to retrieve the attributes of other entity with the value retrived above.

    e.g

    DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
    Picklist pick = (Picklist)entity.Properties["pag_clientname"];
    String getClient_name = pick.name;

     crmservice.ColumnSet cols = new crmservice.ColumnSet(); //pag_clientid is lookuptype attribute
     cols.Attributes = new String[] { "pag_clientid", "pag_name" };

                    crmservice.QueryByAttribute query = new crmservice.QueryByAttribute();
                    query.Attributes = new string[] { "pag_clientid" };
                    query.Values = new String[] { getClient_name};
                    query.EntityName = crmservice.EntityName.pag_contactperson.ToString();
                    query.ColumnSet = cols;


    Suggesstion?



                   

     

    Friday, July 24, 2009 5:24 AM
  • Hi,
    I am sorry but I am still not clear!
    You need to get pag_clientid  and pag_name from pag_contactperson where pag_clientid='someGuid';

    Or you need to get these information based on pag_client's text and not the guid ?


    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Friday, July 24, 2009 5:37 AM
  • Yup,
    I need to get pag_clientid  and pag_name from pag_contactperson where pag_clientid='someGuid';

    and i know only name of the lookup field not value

    lookup look = "pag_clientid";
    look.name is known



    Friday, July 24, 2009 6:08 AM
  • Hi,

    Okay could you try this and let me know!

     

      crmservice.QueryByAttribute query = new crmservice.QueryByAttribute();
    query.Attributes = new string[] { "pag_clientidname"};


    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Friday, July 24, 2009 6:33 AM
  • pag_clientidname is not an attribute. It won't work.

    Friday, July 24, 2009 7:11 AM
  • Hi,

    Than i guess you need to use sql query against the fiteredview of your pag_contactperson entity.


    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Friday, July 24, 2009 7:45 AM
  • Nishant initial suggestion about using queryexpression is the correct one. But instead of querying the primary table which is the way to go only when you have a lookup id (guid) create a linked entity (join) with the child entity and construct the condition inside the linked entity.

     

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Friday, July 24, 2009 12:12 PM