locked
How to find Serviceappointment by regardingobjectid RRS feed

  • Question

  • Hi Team,

         I would like to find the service appointment by regarding object id. I use below code for retrieve the record. Record is exists in crm but cannot find the record. It always return null.

        What wrong my code?

    I'm still using CRM 4.0.

    _beEntityCollection = DynamicsEntities.GetBusinessEntityCollection(new AllColumns(), "serviceappointment", "regardingobjectid", new object[] { ((Key)_pdynentity.Properties["incidentid"]).Value });


    public static BusinessEntityCollection GetBusinessEntityCollection(ColumnSetBase _columnsetbase, string _entityname,
                                                         string _attributename, object[] _filterid)
            {
                // Create Service
                //CrmService _crmService = CrmWebServices.CrmServices();
                //ICrmService _crmService = CrmWebServices._ICrmService;
                ColumnSetBase _columnsetbases = _columnsetbase;
    
                ConditionExpression cond = new ConditionExpression();
                cond.AttributeName = _attributename;
                cond.Operator = ConditionOperator.Equal;
                cond.Values = _filterid;
    
                FilterExpression filter = new FilterExpression();
                filter.FilterOperator = LogicalOperator.And;
                filter.Conditions.AddRange(new ConditionExpression[] { cond });
                QueryExpression query = new QueryExpression();
                query.ColumnSet = _columnsetbases;
                query.Criteria = filter;
                query.EntityName = _entityname;
    
                RetrieveMultipleRequest _retrievemultiplerequest = new RetrieveMultipleRequest();
                _retrievemultiplerequest.ReturnDynamicEntities = true;
                _retrievemultiplerequest.Query = query;
                RetrieveMultipleResponse _retrievemultipleresponse = null;
                BusinessEntityCollection _businessentitycollection = null;
                CrmService _CrmServiceExe = null;
                ICrmService _ICrmServiceExe = null;
                // Get a new instance of the CRM service from the context
                try
                {
                    if (CrmWebServices._CrmService != null)
                    {
                        _CrmServiceExe = CrmWebServices._CrmService;
                        _retrievemultipleresponse = (RetrieveMultipleResponse)_CrmServiceExe.Execute(_retrievemultiplerequest);
                    }
                    else
                    {
                        _ICrmServiceExe = CrmWebServices._ICrmService;
                        _retrievemultipleresponse = (RetrieveMultipleResponse)_CrmServiceExe.Execute(_retrievemultiplerequest);
                    }
                    _businessentitycollection = _retrievemultipleresponse.BusinessEntityCollection;
                }
                catch (SoapException soapex)
                {
                    XmlNode _xmlnode = soapex.Detail.SelectSingleNode("//error//code");
                    if (_xmlnode.InnerText == "0x80040217")
                        return null;
                    else throw new ApplicationException(soapex.Detail.InnerText, soapex);
                }
                catch (System.NullReferenceException ex)
                {
                    throw new NullReferenceException("An error has occurred in the Service Appointment", ex);
                }
                return _businessentitycollection;
            }

    Regards,

    Yukon


    Make Simple & Easy

    Thursday, December 26, 2013 1:39 PM

All replies

  • Hi Team,

         Case is solved.

    if (CrmWebServices._CrmService != null)
                    {
                        _CrmServiceExe = CrmWebServices._CrmService;
                        _retrievemultipleresponse = (RetrieveMultipleResponse)_CrmServiceExe.Execute(_retrievemultiplerequest);
                    }
                    else
                    {
                        _ICrmServiceExe = CrmWebServices._ICrmService;
                        //_retrievemultipleresponse = (RetrieveMultipleResponse)_CrmServiceExe.Execute(_retrievemultiplerequest); // Here is wrong. Should be ICrmServiceExe 
                       _retrievemultipleresponse = (RetrieveMultipleResponse)ICrmServiceExe .Execute(_retrievemultiplerequest); // Correct one.
                    }

    Regards,

    Yukon


    Make Simple & Easy

    Saturday, December 28, 2013 3:35 PM