好吧,我有以下命令:IOrganizationService.Retrieve(String entityName, Guid ID, ColumnSet columnSet)
参考:IOrganizationService
我尝试了SDK代码示例,但是在创建记录时使用Guid来获取检索信息,例如:Guid _accountId = orgService.Create(account);
我想使用Account(Entity)的名称获取此Guid
,怎么办?
答案 0 :(得分:6)
您必须使用RetrieveMultiple
方法和QueryExpression
来实现。例如,下面的MSDN code example是自我解释的,用于获取与lastname = “Brown”
的联系人
// Query using ConditionExpression and FilterExpression
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "lastname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add("Brown");
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
QueryExpression query = new QueryExpression("contact");
query.ColumnSet.AddColumns("firstname", "lastname");
query.Criteria.AddFilter(filter1);
EntityCollection result1 = _serviceProxy.RetrieveMultiple(query);
Console.WriteLine();Console.WriteLine("Query using Query Expression with ConditionExpression and FilterExpression");
Console.WriteLine("---------------------------------------");
foreach (var a in result1.Entities)
{
Console.WriteLine("Name: " + a.Attributes["firstname"] + " " + a.Attributes["lastname"]);
}
查询表达式用于检索多个记录的方法中,例如 IOrganizationService.RetrieveMultiple 方法,该方法在对由指定的结果集执行操作的消息中查询表达式,例如BulkDeleteRequest和当未知特定记录的ID时。
答案 1 :(得分:2)
我使用查询获得了解决方案:
import os
output_2d_list = []
current_working_directory = os.path.abspath('.')
# Iterates over all files contained within the same folder as the python script.
for filename in os.listdir(current_working_directory):
if filename.endswith('.pts'):
# Ensuring that if something goes wrong during read, that the program exits gracefully.
try:
with open(filename, 'r') as current_file:
# Reads each line of the file, and creates a 1d list of each point: e.g. [1,2].
for line in current_file.readlines():
point = line.split(' ')
x = int(point[0])
y = int(point[1])
point_as_array = [x, y]
output_2d_list.append(point_as_array)
except IOError:
print "Something went wrong when attempting to read file."
# For testing purposes to see the output of the script.
# In production, you would be working with output_2d_list as a variable instead.
print output_2d_list
这将使用帐户名返回Guid信息。
答案 2 :(得分:1)
查询表达式是一种选择。我发现效率最低。寻找更常用的方法: