ExecuteMultipleResponse;如何从响应中读取和存储指南 [英] ExecuteMultipleResponse; How to read and store Guids from the response
问题描述
我正在使用ExecuteMultipleResponse方法通过SSIS一次插入10条帐户记录.
I am using ExecuteMultipleResponse method to insert 10 account records at a time using SSIS.
List<Entity> _Accounts = new List<Entity>();
// Check the batch size and process
public override void InputAccount_ProcessInput(InputAccountBuffer Buffer)
{
//List<int> personIDs = new List<int>();
int index = 0;
while (Buffer.NextRow())
{
_Accounts.Add(InputAccountFromBuffer(Buffer));
//personIDs.Add(int.Parse(Buffer.sPersonID));
index++;
if (index == 10)
{
ImportBatch();
index = 0;
}
}
ImportBatch();
}
private void ImportBatch()
{
if (_Accounts.Count > 0)
{
var multipleRequest = new ExecuteMultipleRequest()
{
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = true,
ReturnResponses = true
},
Requests = new OrganizationRequestCollection()
};
foreach (var profContact in _Accounts)
{
CreateRequest reqCreate = new CreateRequest();
reqCreate.Target = profContact;
reqCreate.Parameters.Add("SuppressDuplicateDetection", false);
multipleRequest.Requests.Add(reqCreate);
}
ExecuteMultipleResponse multipleResponses = (ExecuteMultipleResponse)organizationservice.Execute(multipleRequest);
var responses = (ExecuteMultipleResponseItemCollection)multipleResponses.Results["Responses"];
foreach (var response in responses)
{
if (response.Fault != null)
{
// A fault has occurred, handle it here
}
else
{
// THIS IS WHERE I KNOW THE GUID VALUE EXIST.
}
}
//IEnumerator f = multipleResponses.Responses.GetEnumerator();
_Accounts.Clear();
}
}
上面的代码工作正常,但是,我现在需要读取和存储对列表的响应的Guid.此信息对于包装中的下一步至关重要.我知道,如果我要创建单个记录,我可以简单地说,
Above code is working fine, however, I now need to read and store Guids from response to a List. This information is essential for the next step in the package. I know, if I am creating single record I can simply say,
Guid newRecord = _service.Create(account);
我什至设法检查响应是否有故障",如果没有故障,则响应中应该存在Guid值.
I even managed to get down to check if the response have 'Fault' or not and if it doesn't have fault then Guid value should exist in the response.
QuickWatch中运行的response.Response.Results.Values向我显示了GUID,但我找不到直接读取并存储为GUID的方法.
Running response.Response.Results.Values in QuickWatch shows me the guid but I just can't find a way to read it directly and store it as a Guid.
推荐答案
已创建记录的guid应该存储在OrganizationResponse
中,该文件可以在ExecuteMultipleResponseItem
内部找到
尝试以下操作以将GUID作为字符串获取:
The guid of a created record should be stored in the OrganizationResponse
which can be found inside the ExecuteMultipleResponseItem
Try the following to get the guid as a string:
string id = response.Response.Results["id"].ToString()
如果它能按预期工作,则您还可以在需要时实例化guid:
If it works as expected you should also be able to instantiate a guid, if needed:
Guid guid = new Guid(id);
这篇关于ExecuteMultipleResponse;如何从响应中读取和存储指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!