本文整理汇总了C#中IOrganizationService.Retrieve方法的典型用法代码示例。如果您正苦于以下问题:C# IOrganizationService.Retrieve方法的具体用法?C# IOrganizationService.Retrieve怎么用?C# IOrganizationService.Retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOrganizationService
的用法示例。
在下文中一共展示了IOrganizationService.Retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateRank
public static int UpdateRank(IOrganizationService service, Entity workflow)
{
var wf = service.Retrieve("workflow", workflow.Id, new ColumnSet("statecode"));
if (wf.GetAttributeValue<OptionSetValue>("statecode").Value != 0)
{
service.Execute(new SetStateRequest
{
EntityMoniker = wf.ToEntityReference(),
State = new OptionSetValue(0),
Status = new OptionSetValue(-1)
});
}
workflow.Attributes.Remove("statecode");
workflow.Attributes.Remove("statuscode");
service.Update(workflow);
if (wf.GetAttributeValue<OptionSetValue>("statecode").Value != 0)
{
service.Execute(new SetStateRequest
{
EntityMoniker = wf.ToEntityReference(),
State = new OptionSetValue(1),
Status = new OptionSetValue(-1)
});
}
return workflow.GetAttributeValue<int>("rank");
}
示例2: FakeRetrieve
/// <summary>
/// A fake retrieve method that will query the FakedContext to retrieve the specified
/// entity and Guid, or null, if the entity was not found
/// </summary>
/// <param name="context">The faked context</param>
/// <param name="fakedService">The faked service where the Retrieve method will be faked</param>
/// <returns></returns>
protected static void FakeRetrieve(XrmFakedContext context, IOrganizationService fakedService)
{
A.CallTo(() => fakedService.Retrieve(A<string>._, A<Guid>._, A<ColumnSet>._))
.ReturnsLazily((string entityName, Guid id, ColumnSet columnSet) =>
{
if (string.IsNullOrWhiteSpace(entityName))
{
throw new InvalidOperationException("The entity logical name must not be null or empty.");
}
if (id == Guid.Empty)
{
throw new InvalidOperationException("The id must not be empty.");
}
if (columnSet == null)
{
throw new InvalidOperationException("The columnset parameter must not be null.");
}
// Don't fail with invalid operation exception, if no record of this entity exists, but entity is known
if (!context.Data.ContainsKey(entityName))
{
if (context.ProxyTypesAssembly == null)
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
if (!context.ProxyTypesAssembly.GetTypes().Any(type => context.FindReflectedType(entityName) != null))
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
}
//Entity logical name exists, so , check if the requested entity exists
if (context.Data.ContainsKey(entityName) && context.Data[entityName] != null
&& context.Data[entityName].ContainsKey(id))
{
//Entity found => return only the subset of columns specified or all of them
if (columnSet.AllColumns)
return context.Data[entityName][id];
else
{
//Return the subset of columns requested only
var foundEntity = context.Data[entityName][id];
Entity projected = foundEntity.ProjectAttributes(columnSet,context);
return projected;
}
}
else
{
//Entity not found in the context => return null
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("{0} With Id = {1} Does Not Exist", entityName, id.ToString("D")));
}
});
}
示例3: GetUnmanagedSolutions
public static List<CrmSolution> GetUnmanagedSolutions(IOrganizationService service)
{
var qba = new QueryByAttribute("solution") { ColumnSet = new ColumnSet("friendlyname", "publisherid") };
qba.Attributes.AddRange("ismanaged", "isvisible");
qba.Values.AddRange(false, true);
var solutions = service.RetrieveMultiple(qba);
return (from solution in solutions.Entities
let publisher =
service.Retrieve("publisher", solution.GetAttributeValue<EntityReference>("publisherid").Id,
new ColumnSet("customizationprefix"))
select
new CrmSolution(solution.GetAttributeValue<string>("friendlyname"),
publisher.GetAttributeValue<string>("customizationprefix"))).ToList();
}
示例4: CreateCrmAccount2
/// <summary>
/// Creates a new account with a given name and then creates a follow-up task linked to the account
/// </summary>
/// <param name="accountName">account name</param>
/// <param name="service">organization service</param>
public static void CreateCrmAccount2(string accountName, IOrganizationService service)
{
//create the account
Entity account = new Entity("account");
account["name"] = accountName;
Guid newId = service.Create(account);
//get the account number
account = service.Retrieve("account", newId, new Microsoft.Xrm.Sdk.Query.ColumnSet(new string[] { "name", "accountid", "accountnumber" }));
string accountNumber = account["accountnumber"].ToString();
//create the task
Entity task = new Entity("task");
task["subject"] = "Finish account set up for " + accountName + " - " + accountNumber;
task["regardingobjectid"] = new Microsoft.Xrm.Sdk.EntityReference("account", newId);
service.Create(task);
}
示例5: PrepareFormTabs
public void PrepareFormTabs(ExcelWorksheet sheet, IOrganizationService service, List<Entity> forms)
{
var rowsCount = sheet.Dimension.Rows;
var cellsCount = sheet.Dimension.Columns;
for (var rowI = 1; rowI < rowsCount; rowI++)
{
var tabId = ZeroBasedSheet.Cell(sheet, rowI, 0).Value.ToString();
var formId = new Guid(ZeroBasedSheet.Cell(sheet, rowI, 3).Value.ToString());
var form = forms.FirstOrDefault(f => f.Id == formId);
if (form == null)
{
form = service.Retrieve("systemform", formId, new ColumnSet(new[] { "formxml" }));
forms.Add(form);
}
// Load formxml
var formXml = form.GetAttributeValue<string>("formxml");
var docXml = new XmlDocument();
docXml.LoadXml(formXml);
var tabNode = docXml.DocumentElement.SelectSingleNode(string.Format("tabs/tab[translate(@id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{0}']", tabId.ToLower()));
if (tabNode != null)
{
var columnIndex = 4;
while (columnIndex < cellsCount)
{
if (ZeroBasedSheet.Cell(sheet, rowI, columnIndex).Value != null)
{
var lcid = ZeroBasedSheet.Cell(sheet, 0, columnIndex).Value.ToString();
var label = ZeroBasedSheet.Cell(sheet, rowI, columnIndex).Value.ToString();
UpdateXmlNode(tabNode, lcid, label);
}
columnIndex++;
}
}
form["formxml"] = docXml.OuterXml;
}
}
示例6: GetProductInfoNumberFromId
private void GetProductInfoNumberFromId(Guid productid, ref IOrganizationService service, ref string productnumber, ref string new_sigaccref)
{
QueryExpression myProductIDQuery = new QueryExpression
{
EntityName = "product",
ColumnSet = new ColumnSet("productnumber"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "productid",
Operator = ConditionOperator.Equal,
Values = {productid}
}
}
}
};
var entity = service.Retrieve("product", productid, new ColumnSet("productnumber"));
productnumber = entity.GetAttributeValue<string>("productnumber");
new_sigaccref = entity.GetAttributeValue<string>("new_sigaccref");
}
示例7: getTimeEntryEntityId
private Entity getTimeEntryEntityId(IOrganizationService service, Guid timeEntryGuid)
{
return service.Retrieve("gsc_timeentry",
timeEntryGuid,
new ColumnSet("gsc_timeentryid"));
}
示例8: CalculateInvoiceProduct
// Method to calculate extended amount in the product line items in an invoice
private static void CalculateInvoiceProduct(EntityReference entity, IOrganizationService service)
{
try
{
ColumnSet columns = new ColumnSet();
Entity e = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("quantity", "priceperunit", "invoiceispricelocked"));
Entity e1 = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("quantity", "invoiceispricelocked"));
decimal total = 0;
total = total + ((decimal)e["quantity"] * ((Money)e["priceperunit"]).Value);
e1["extendedamount"] = new Money(total);
service.Update(e1);
}
catch (FaultException<OrganizationServiceFault> ex)
{
System.Diagnostics.Debug.Write(ex.Message);
}
}
示例9: Run
/// <summary>
/// This method first connects to the organization service. Next, auditing
/// is enabled on the organization and an account entity. The account record
/// is updated and the audit history printed out.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
{
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
{
// Enable early-bound type support.
_serviceProxy.EnableProxyTypes();
// You can access the service through the proxy, but this sample uses the interface instead.
_service = _serviceProxy;
#region Enable Auditing for an Account
//<snippetAuditing1>
Console.WriteLine("Enabling auditing on the organization and account entities.");
// Enable auditing on the organization.
// First, get the organization's ID from the system user record.
Guid orgId = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).OrganizationId;
// Next, retrieve the organization's record.
Organization org = _service.Retrieve(Organization.EntityLogicalName, orgId,
new ColumnSet(new string[] { "organizationid", "isauditenabled" })) as Organization;
// Finally, enable auditing on the organization.
bool organizationAuditingFlag = org.IsAuditEnabled.Value;
org.IsAuditEnabled = true;
_service.Update(org);
// Enable auditing on account entities.
bool accountAuditingFlag = EnableEntityAuditing(Account.EntityLogicalName, true);
//</snippetAuditing1>
#endregion Enable Auditing for an Account
CreateRequiredRecords();
#region Retrieve the Record Change History
Console.WriteLine("Retrieving the account change history.\n");
//<snippetAuditing5>
// Retrieve the audit history for the account and display it.
RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
changeRequest.Target = new EntityReference(Account.EntityLogicalName, _newAccountId);
RetrieveRecordChangeHistoryResponse changeResponse =
(RetrieveRecordChangeHistoryResponse)_service.Execute(changeRequest);
AuditDetailCollection details = changeResponse.AuditDetailCollection;
//</snippetAuditing5>
foreach (AttributeAuditDetail detail in details.AuditDetails)
{
// Display some of the detail information in each audit record.
DisplayAuditDetails(detail);
}
#endregion Retrieve the Record Change History
#region Retrieve the Attribute Change History
//<snippetAuditing7>
// Update the Telephone1 attribute in the Account entity record.
Account accountToUpdate = new Account();
accountToUpdate.AccountId = _newAccountId;
accountToUpdate.Telephone1 = "123-555-5555";
_serviceProxy.Update(accountToUpdate);
Console.WriteLine("Updated the Telephone1 field in the Account entity.");
// Retrieve the attribute change history.
Console.WriteLine("Retrieving the attribute change history for Telephone1.");
var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest
{
Target = new EntityReference(
Account.EntityLogicalName, _newAccountId),
AttributeLogicalName = "telephone1"
};
var attributeChangeHistoryResponse =
(RetrieveAttributeChangeHistoryResponse)_service.Execute(attributeChangeHistoryRequest);
// Display the attribute change history.
details = attributeChangeHistoryResponse.AuditDetailCollection;
//</snippetAuditing7>
foreach (var detail in details.AuditDetails)
{
DisplayAuditDetails(detail);
}
// Save an Audit record ID for later use.
Guid auditSampleId = details.AuditDetails.First().AuditRecord.Id;
#endregion Retrieve the Attribute Change History
#region Retrieve the Audit Details
//<snippetAuditing8>
//.........这里部分代码省略.........
示例10: Run
/// <summary>
/// Create and configure the organization service proxy.
/// Create an account record
/// Retrieve the account record
/// Update the account record
/// Optionally delete any entity records that were created for this sample.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptForDelete">When True, the user will be prompted to delete
/// all created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
{
try
{
// Connect to the Organization service.
// The using statement assures that the service proxy will be properly disposed.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
{
_service = (IOrganizationService)_serviceProxy;
//<snippetCRUDOperationsDE1>
// Instaniate an account object.
Entity account = new Entity("account");
// Set the required attributes. For account, only the name is required.
// See the Entity Metadata topic in the SDK documentatio to determine
// which attributes must be set for each entity.
account["name"] = "Fourth Coffee";
// Create an account record named Fourth Coffee.
_accountId = _service.Create(account);
Console.Write("{0} {1} created, ", account.LogicalName, account.Attributes["name"]);
// Create a column set to define which attributes should be retrieved.
ColumnSet attributes = new ColumnSet(new string[] { "name", "ownerid" });
// Retrieve the account and its name and ownerid attributes.
account = _service.Retrieve(account.LogicalName, _accountId, attributes);
Console.Write("retrieved, ");
// Update the postal code attribute.
account["address1_postalcode"] = "98052";
// The address 2 postal code was set accidentally, so set it to null.
account["address2_postalcode"] = null;
// Shows use of Money.
account["revenue"] = new Money(5000000);
// Shows use of boolean.
account["creditonhold"] = false;
// Update the account.
_service.Update(account);
Console.WriteLine("and updated.");
// Delete the account.
bool deleteRecords = true;
if (promptForDelete)
{
Console.WriteLine("\nDo you want these entity records deleted? (y/n) [y]: ");
String answer = Console.ReadLine();
deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y") || answer == String.Empty);
}
if (deleteRecords)
{
_service.Delete("account", _accountId);
Console.WriteLine("Entity record(s) have been deleted.");
}
//</snippetCRUDOperationsDE1>
}
}
// 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;
}
}
示例11: ReplaceParameters
private string ReplaceParameters(string text, Entity Target, IOrganizationService Service)
{
if (String.IsNullOrWhiteSpace(text))
{
return "";
}
foreach (RuntimeParameter param in RuntimeParameter.GetParametersFromString(text))
{
if (!param.IsParentParameter())
{
text = text.Replace(param.ParameterText, param.GetParameterValue(Target));
}
else
{
if (Target.Contains(param.ParentLookupName))
{
var parentRecord = Service.Retrieve(Target.GetAttributeValue<EntityReference>(param.ParentLookupName).LogicalName, Target.GetAttributeValue<EntityReference>(param.ParentLookupName).Id, new ColumnSet(param.AttributeName));
text = text.Replace(param.ParameterText, param.GetParameterValue(parentRecord));
}
else // Target record has no parent, so use default value
{
text = text.Replace(param.ParameterText, param.DefaultValue);
}
}
}
return text;
}
示例12: GetDefaultPublisher
/// <summary>
/// Gets the default publisher.
/// </summary>
/// <param name="service">The service.</param>
/// <returns>EntityReference.</returns>
public static EntityReference GetDefaultPublisher(IOrganizationService service)
{
// Retrieve the Default Publisher
var defaultPublisher = service.Retrieve(EntityName.publisher,
new Guid(ParameterName.DefaultPublisherId),
new ColumnSet(publisher.friendlyname));
var referecnce = new EntityReference
{
Id = defaultPublisher.Id,
LogicalName = EntityName.publisher,
Name = publisher.friendlyname
};
return referecnce;
}
示例13: EnableOrDisableAuditing
/// <summary>
/// Enables or disable organiztion's auditing.
/// </summary>
/// <param name="crmService">The CRM service.</param>
/// <param name="enableAuditing">if set to <c>true</c> [enable auditing].</param>
public static void EnableOrDisableAuditing(IOrganizationService crmService, bool enableAuditing)
{
// Enable auditing on the organization.
// First, get the organization's ID from the system user record.
var orgId = ((WhoAmIResponse) crmService.Execute(new WhoAmIRequest())).OrganizationId;
// Next, retrieve the organization's record.
// Next, retrieve the organization's record.
var org = crmService.Retrieve(EntityName.organization, orgId,
new ColumnSet(organization.organizationid, organization.isauditenabled));
org[organization.isauditenabled] = enableAuditing;
crmService.Update(org);
}
示例14: Invoke_Retrieve_Check_Cache
public virtual void Invoke_Retrieve_Check_Cache(IOrganizationService service)
{
// Act
var result = service.Retrieve(string.Empty, Guid.Empty, new ColumnSet());
// Assert
result.Should().NotBe(null);
result.ShouldBeEquivalentTo(expectedResultRetrieve, options => options.Excluding(x => x.ExtensionData));
((CuteService)service).Provider.Calls.Where(x => x.Message == MessageName.Retrieve).Count().Should().Be(1);
}
示例15: isTrust
private bool isTrust(EntityReference new_accountid, IOrganizationService service)
{
var isTrust = service.Retrieve("account", new_accountid.Id, new ColumnSet("new_trust"));
if ( isTrust == null || isTrust.GetAttributeValue<bool?>("new_trust") == null )
return false;
return isTrust.GetAttributeValue<bool>("new_trust");
}