ClientUI.ViewModel.ObservableConnection.RoleSearch C# (CSharp) Method

RoleSearch() private method

private RoleSearch ( string term, Action callback, string typeName ) : void
term string
callback Action
typeName string
return void
        public static void RoleSearch(string term, Action<EntityCollection> callback,string typeName)
        {
            string recordTypeFilter = string.Empty;

            if (typeName != null)
            {
                // find the entity type code from the type name
                int? etc = GetEntityTypeCodeFromName(typeName);
                // Filter by the currently select role
                recordTypeFilter = String.Format(@"
                                        <filter type='or'>
                                            <condition attribute='associatedobjecttypecode' operator='eq' value='{0}' />
                                            <condition attribute='associatedobjecttypecode' operator='eq' value='0' />
                                        </filter>", etc);
            }
            string fetchXml = @"
                            <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true' >
                                <entity name='connectionrole' >
                                    <attribute name='category' />
                                    <attribute name='name' />
                                    <attribute name='connectionroleid' />
                                    <attribute name='statecode' />
                                    <order attribute='name' descending='false' />
                                    <link-entity name='connectionroleobjecttypecode' from='connectionroleid' to='connectionroleid' >
                                    {1}
                                    </link-entity>
                                    <filter type='and'>
                                        <condition attribute='name' operator='like' value='%{0}%' />
                                    </filter>
                                </entity>
                            </fetch>";

            fetchXml = string.Format(fetchXml, XmlHelper.Encode(term), recordTypeFilter);
            OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object result)
            {

                EntityCollection fetchResult = OrganizationServiceProxy.EndRetrieveMultiple(result, typeof(Entity));
                callback(fetchResult);
            });
        }

Usage Example

 public void RoleSearchCommand(string term, Action <EntityCollection> callback)
 {
     // Get the possible roles
     ObservableConnection.RoleSearch(term, callback, SelectedConnection.GetValue().Record2Id.LogicalName);
 }