locked
Cannot retrieve custom attribute correct value in multi tenancy environment RRS feed

  • Question

  • Hi All,

    I am in a strangle situation where I am not able to get the correct value of a custom attribute(bit)'s correct value using Crm Sdk. Its a multi tenancy environment. 

    There are two organizations, for first organization it all goes right, but for the other no matter how I set the attribute value either using the CRM interface or also going myself to database and seeing what the value is, but the Sdk would always return me a false value for this bit attribute.

    I have also tried it by setting CrmService object 's url property to the format http://servername:5555/MSCrmServices/2007/CrmService.asmx?uniquename=orgName. but of no use.

    Regards,
    Haris Munawar
    Wednesday, May 20, 2009 7:18 AM

Answers

  • Hi,

    My problem is resolved. Actually I was using the following code for retrieving userId and also for running any Crm requests.

             	using (new Microsoft.Crm.Sdk.CrmImpersonator())
                    {
                        this.Authenticate();
    
                        Microsoft.Crm.Sdk.CrmAuthenticationToken sdkToken =
                            Microsoft.Crm.Sdk.CrmAuthenticationToken.ExtractCrmAuthenticationToken(this.HttpContext,
                            System.Configuration.ConfigurationManager.AppSettings["Organization"]);
                        id = sdkToken.CallerId;
    
                        QueryByAttribute query = new QueryByAttribute();
                        query.ColumnSet = new AllColumns();
                        query.EntityName = EntityName.systemuser.ToString();
                        query.Attributes = new string[] { "systemuserid" };
                        query.Values = new string[] { id.ToString() };
                        retrieved = service.RetrieveMultiple(query);
                        userOption = ((systemuser)retrieved.BusinessEntities[0]).CustomAttribute;
    		}
    For the default organization or the first organization this code worked fine i.e. UserId taken from the token.CallerId was the correct one. For the other organization, the token.callerId was the same as of the default organization which was causing problems and I was not able to actually retrieve the User. 

    Now, I am using WhoAmIRequest for retrieving userId.

    This is strange that why token.CallerId is always of the default organization's user. Maybe this is a bug or maybe something more has to be done for it to give us the correct userId.

    Regards,
    Haris Munawar
    Wednesday, May 20, 2009 11:51 AM

All replies

  • Hi Haris,
     

    Here are few things that might help you identify the problem.

    1- Can you access the second organization webservice if you paste the http://servername:5555/MSCrmServices/2007/CrmService.asmx?uniquename=orgName URL in the browser?
    2- Step through your code and see if you get any errors when your code executes.
    3- If you cannot see anything obvious try and do a retrieve on another field and see if you can read the value.

    Please post back if you find the solution.

    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, May 20, 2009 8:12 AM
  • Hi,

    My problem is resolved. Actually I was using the following code for retrieving userId and also for running any Crm requests.

             	using (new Microsoft.Crm.Sdk.CrmImpersonator())
                    {
                        this.Authenticate();
    
                        Microsoft.Crm.Sdk.CrmAuthenticationToken sdkToken =
                            Microsoft.Crm.Sdk.CrmAuthenticationToken.ExtractCrmAuthenticationToken(this.HttpContext,
                            System.Configuration.ConfigurationManager.AppSettings["Organization"]);
                        id = sdkToken.CallerId;
    
                        QueryByAttribute query = new QueryByAttribute();
                        query.ColumnSet = new AllColumns();
                        query.EntityName = EntityName.systemuser.ToString();
                        query.Attributes = new string[] { "systemuserid" };
                        query.Values = new string[] { id.ToString() };
                        retrieved = service.RetrieveMultiple(query);
                        userOption = ((systemuser)retrieved.BusinessEntities[0]).CustomAttribute;
    		}
    For the default organization or the first organization this code worked fine i.e. UserId taken from the token.CallerId was the correct one. For the other organization, the token.callerId was the same as of the default organization which was causing problems and I was not able to actually retrieve the User. 

    Now, I am using WhoAmIRequest for retrieving userId.

    This is strange that why token.CallerId is always of the default organization's user. Maybe this is a bug or maybe something more has to be done for it to give us the correct userId.

    Regards,
    Haris Munawar
    Wednesday, May 20, 2009 11:51 AM