Last active
January 4, 2024 09:03
-
-
Save melamriD365/06fc71bfbcc11a30670f73deb1d122b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Xrm.Sdk; | |
using Microsoft.Xrm.Sdk.Client; | |
using Microsoft.Xrm.Sdk.Query; | |
using System; | |
using System.ServiceModel.Description; | |
namespace MelTools | |
{ | |
class getAllUsersPersonalViewsContainingField | |
{ | |
static void Main(string[] args) | |
{ | |
ClientCredentials clientCredentials = new ClientCredentials(); | |
clientCredentials.UserName.UserName = "xxx"; | |
clientCredentials.UserName.Password = "xxx"; | |
OrganizationServiceProxy organizationService = new OrganizationServiceProxy(new Uri("https://yourOrganization.crm4.dynamics.com/XRMServices/2011/Organization.svc"), null, clientCredentials, null); | |
// Instantiate QueryExpression QEsystemuser | |
var QEsystemuser = new QueryExpression("systemuser"); | |
// Add all columns to QEsystemuser.ColumnSet | |
QEsystemuser.ColumnSet.AllColumns = true; | |
EntityCollection users = organizationService.RetrieveMultiple(QEsystemuser); | |
foreach (var user in users.Entities) | |
{ | |
try | |
{ | |
organizationService.CallerId = user.Id; | |
// Define Condition Values | |
var QEuserquery_fetchxml_entity = "%<entity name=\"contact\">%"; | |
var QEuserquery_fetchxml_field= "%<attribute name=\"mel_contactnumber\"/>%"; | |
// Instantiate QueryExpression QEuserquery | |
var QEuserquery = new QueryExpression("userquery"); | |
// Add all columns to QEuserquery.ColumnSet | |
QEuserquery.ColumnSet.AllColumns = true; | |
// Define filter QEuserquery.Criteria | |
QEuserquery.Criteria.AddCondition("fetchxml", ConditionOperator.Like, QEuserquery_fetchxml_entity); | |
QEuserquery.Criteria.AddCondition("fetchxml", ConditionOperator.Like, QEuserquery_fetchxml_field); | |
EntityCollection personalViews = organizationService.RetrieveMultiple(QEuserquery); | |
if (personalViews.Entities.Count > 0) | |
{ | |
foreach (var personalView in personalViews.Entities) | |
{ | |
Console.WriteLine("view name: " + personalView.GetAttributeValue<string>("name") + "| owner: " + personalView.GetAttributeValue<EntityReference>("ownerid").Name); | |
} | |
} | |
} | |
catch (Exception e) { } | |
} | |
Console.WriteLine("click to exit"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment