本文整理汇总了C#中OrganizationService.Retrieve方法的典型用法代码示例。如果您正苦于以下问题:C# OrganizationService.Retrieve方法的具体用法?C# OrganizationService.Retrieve怎么用?C# OrganizationService.Retrieve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrganizationService
的用法示例。
在下文中一共展示了OrganizationService.Retrieve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeStateCode
private static bool? ChangeStateCode(Guid id)
{
var service = new OrganizationService(connection);
SetStateRequest state = new SetStateRequest();
state.State = new OptionSetValue((int)TaskState.Completed);
state.Status =
new OptionSetValue(5);
state.EntityMoniker = new EntityReference()
{
Id = id,
LogicalName = SoftLine.Models.Task.EntityLogicalName
};
SetStateResponse stateSet = (SetStateResponse)service.Execute(state);
SoftLine.Models.Task task =
service.Retrieve(SoftLine.Models.Task.EntityLogicalName, id, new ColumnSet("statecode")).ToEntity<SoftLine.Models.Task>();
if (task.StateCode == TaskState.Completed)
{
return true;
}
return null;
}
示例2: Run
/// <summary>
/// The Run() method first connects to the organization service. Afterwards,
/// basic create, retrieve, update, and delete entity operations are performed.
/// </summary>
/// <param name="connectionString">Provides service connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(String connectionString, bool promptforDelete)
{
try
{
// Establish a connection to the organization web service.
Print("Connecting to the server ...");
Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(connectionString);
// Obtain an organization service proxy.
// The using statement assures that the service proxy will be properly disposed.
using (_orgService = new OrganizationService(connection))
{
Print("connected");
Print("Authenticating the user ...");
// Create any entity records this sample requires.
CreateRequiredRecords();
// Obtain information about the logged on user from the web service.
Guid userid = ((WhoAmIResponse)_orgService.Execute(new WhoAmIRequest())).UserId;
SystemUser systemUser = (SystemUser)_orgService.Retrieve("systemuser", userid,
new ColumnSet(new string[] { "firstname", "lastname" }));
Println("Logged on user is " + systemUser.FirstName + " " + systemUser.LastName + ".");
// Retrieve the version of Microsoft Dynamics CRM.
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
RetrieveVersionResponse versionResponse =
(RetrieveVersionResponse)_orgService.Execute(versionRequest);
Println("Microsoft Dynamics CRM version " + versionResponse.Version + ".");
// Instantiate an account object. Note the use of option set enumerations defined in OptionSets.cs.
// Refer to the Entity Metadata topic in the SDK documentation to determine which attributes must
// be set for each entity.
Account account = new Account { Name = "Fourth Coffee" };
account.AccountCategoryCode = new OptionSetValue((int)AccountAccountCategoryCode.PreferredCustomer);
account.CustomerTypeCode = new OptionSetValue((int)AccountCustomerTypeCode.Investor);
// Create an account record named Fourth Coffee.
_accountId = _orgService.Create(account);
Println(account.LogicalName + " " + account.Name + " created, ");
// Retrieve several attributes from the new account.
ColumnSet cols = new ColumnSet(
new String[] { "name", "address1_postalcode", "lastusedincampaign" });
Account retrievedAccount = (Account)_orgService.Retrieve("account", _accountId, cols);
Print("retrieved, ");
// Update the postal code attribute.
retrievedAccount.Address1_PostalCode = "98052";
// The address 2 postal code was set accidentally, so set it to null.
retrievedAccount.Address2_PostalCode = null;
// Shows use of a Money value.
retrievedAccount.Revenue = new Money(5000000);
// Shows use of a Boolean value.
retrievedAccount.CreditOnHold = false;
// Update the account record.
_orgService.Update(retrievedAccount);
Print("and updated.");
// Delete any entity records this sample created.
DeleteRequiredRecords(promptforDelete);
}
}
// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
// You can handle an exception here or pass it back to the calling method.
throw;
}
}
示例3: UpdateStatus
public void UpdateStatus(ServiceRequest serviceRequest)
{
var idOfUpdatedItem = serviceRequest.SRID;
//Login and connect to the server and create the context
var connection = ConnectToDatabase();
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
//Gather the components for the "Retrieve" function
ColumnSet set = new ColumnSet();
set.AllColumns = true;
Guid incidentGuid = GetGUIDByName(idOfUpdatedItem, service);
//Retrieves the record that will be updated
var incident = service.Retrieve("incident", incidentGuid, set);
EventLog.saveMessage("Update Status of SRID:" + serviceRequest.SRID);
try
{
// Actual UPDATE of the record.
incident["description"] = serviceRequest.LongDescription;
incident["statuscode"] = ReturnStatusCode(serviceRequest.ServiceRequestStatus);
incident["subjectid"] = ReturnRequestType(serviceRequest.ServiceRequestType);
incident["new_moduleoptionset"] = ReturnModuleCode("TS");
//incident["ownerid"] = new EntityReference("systemuser", findConsultantID(serviceRequest.AssignedPerson,service));
incident["new_statushistory"] = serviceRequest.CommentsMatricia;
incident["casetypecode"] = returnRequestKind(serviceRequest.ServiceRequestKind);
incident["new_caseasignedto"] = serviceRequest.AssignedPerson;
//incident["followupby"] = serviceRequest.DueDate;
incident["title"] = serviceRequest.AssignedToClient + " " + serviceRequest.SRID + " " + serviceRequest.companyName;
//incident["customerid"] = new EntityReference("account", findCustomer((string)serviceRequest.companyName, service));
incident["customerid"] = new EntityReference("account", findCustomerID(serviceRequest.companyName));
incident["new_statushistory"] = serviceRequest.ShortDescription;
incident["new_assignedfrom"] = serviceRequest.CreatedBy;
Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service);
//Assign a case!
service.Update(incident);
EventLog.saveMessage("Start of Assignment! to :" + consultantID);
AssignRequest assignRequest = new AssignRequest();
assignRequest.Assignee = new EntityReference("systemuser", consultantID);
assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid);
service.Execute(assignRequest);
}
catch (Exception)
{
EventLog.saveMessage("This record is unavailable for update right now!" + serviceRequest.SRID);
return;
}
}
示例4: UpdateAssignedPerson
public void UpdateAssignedPerson(ServiceRequest serviceRequest)
{
var idOfUpdatedItem = serviceRequest.SRID;
var connection = ConnectToDatabase();
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service);
ColumnSet set = new ColumnSet();
set.AllColumns = true;
//Gather the components for the "Retrieve" function
Guid incidentGuid = GetGUIDByName(idOfUpdatedItem, service);
//Retrieves the record that will be updated
var incident = service.Retrieve("incident", incidentGuid, set);
EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson);
try
{
//Assign a case!
AssignRequest assignRequest = new AssignRequest();
assignRequest.Assignee = new EntityReference("systemuser", consultantID);
assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid);
//sets the new User.
//incident["ownerid"] = new EntityReference("systemuser", consultantID);
service.Update(incident);
service.Execute(assignRequest);
}
catch (Exception)
{
EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson + " failed!");
return;
}
}
示例5: GetUserNameByEmail
//receives a email of type string
//returns NULL if you users with specified email exist
//returns a string containing the first user with specified email
public override string GetUserNameByEmail(string email)
{
//bcd
using (OrganizationService service = new OrganizationService(OurConnect()))
{
ConditionExpression emailCondition = new ConditionExpression();
ConditionExpression deleteCondition = new ConditionExpression();
ConditionExpression appCondition = new ConditionExpression();
emailCondition.AttributeName = consts.email;
emailCondition.Operator = ConditionOperator.Equal;
emailCondition.Values.Add(email);
deleteCondition.AttributeName = consts.deleteduser;
deleteCondition.Operator = ConditionOperator.Equal;
deleteCondition.Values.Add(false);
appCondition.AttributeName = consts.appname;
appCondition.Operator = ConditionOperator.Equal;
appCondition.Values.Add(_ApplicationName);
FilterExpression filter = new FilterExpression();
filter.Conditions.Add(emailCondition);
filter.Conditions.Add(deleteCondition);
filter.Conditions.Add(appCondition);
QueryExpression query = new QueryExpression(consts.useraccount);
query.ColumnSet.AddColumn(consts.username);
query.Criteria.AddFilter(filter);
EntityCollection collection = service.RetrieveMultiple(query);
if (collection.Entities.Count == 0)
return null;
else
{
Guid Retrieve_ID = collection[0].Id;
ColumnSet attributies = new ColumnSet(new string[] { consts.username });
Entity retrievedEntity = service.Retrieve(consts.useraccount, Retrieve_ID, attributies);
return retrievedEntity[consts.username].ToString();
}
}
}
示例6: GetUser
//receives a provider use key object and user online status boolean value
//returns NULL if user is not online
//returns Membership user type of user specified by provider user key object
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
//MAS
using (OrganizationService service = new OrganizationService(OurConnect()))
{
ColumnSet attributes = new ColumnSet(new string[] { consts.username, consts.online, consts.appname, consts.deleteduser });
Entity e = service.Retrieve(consts.useraccount, (Guid)providerUserKey, attributes);
if (userIsOnline == (bool)e[consts.online] && (string)e[consts.appname] == _ApplicationName && (bool)e[consts.deleteduser] == false)//TODO: make sure bool is casted
return GetUser((string)e[consts.username]);
return null;
}
}
示例7: GetSystemUser
public static Entity GetSystemUser(Guid userid, OrganizationService service)
{
Entity systemuser = service.Retrieve("systemuser", userid, new ColumnSet(true));
return systemuser;
}
示例8: DownloadWebResource
private void DownloadWebResource(Guid webResourceId)
{
DisplayStatusMessage("Downloading file");
string connString = ((CrmConn)Connections.SelectedItem).ConnectionString;
CrmConnection connection = CrmConnection.Parse(connString);
using (OrganizationService orgService = new OrganizationService(connection))
{
Entity webResource = orgService.Retrieve("webresource", webResourceId, new ColumnSet("content", "name"));
var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
if (dte == null)
return;
string projectName = ((ComboBoxItem)Projects.SelectedItem).Content.ToString();
foreach (Project project in dte.Solution.Projects)
{
if (project.Name != projectName) continue;
string[] name = webResource.GetAttributeValue<string>("name").Split('/');
var path = Path.GetDirectoryName(project.FullName) + "\\" + name[name.Length - 1];
FileInfo file = new FileInfo(path);
StreamWriter sw = file.CreateText();
sw.Write(DecodeString(webResource.GetAttributeValue<string>("content")));
sw.Close();
project.ProjectItems.AddFromFile(path);
}
}
DisplayStatusMessage(String.Empty);
}