ExecuteMultipleResponse; How to read and store Guids from the response

蹲街弑〆低调 提交于 2019-12-01 08:29:09

问题


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();
    }

}

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);

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.

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.


回答1:


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()

If it works as expected you should also be able to instantiate a guid, if needed:

Guid guid = new Guid(id);


来源:https://stackoverflow.com/questions/31535952/executemultipleresponse-how-to-read-and-store-guids-from-the-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!