web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Sequence contains more than one element

(0) ShareShare
ReportReport
Posted on by

Hi

The following line in C# plugin is causing an error:

_service.Update(app);

The error is:

Sequence contains more than one element.

Any idea?

Thx

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Unfortunately your code and error can't give exact answer what's wrong. Please post here rest of code and detailed exception.

  • Community Member Profile Picture
    on at
    Here is the code:

    case "449930007": { Guid tempusr = Guid.Empty; Guid ioReviewerID = ((EntityReference)app["gits_io"]).Id; tempusr = getUserformReviewer(ioReviewerID); Entity ent = new Entity(gitsPluginEntity.LogicalName); ent["gits_statusreport"] = new OptionSetValue(449930031); ent["gits_herureviewfid"] = gitsPluginEntity["gits_herureviewfid"]; // ent["gits_nextuser"] = new EntityReference("systemuser", tempusr); if (gitsPluginEntity.Contains("gits_remarks")) ent["gits_remarks"] = gitsPluginEntity["gits_remarks"]; _service.Create(ent); shareRecord(app, tempusr); string GlobaloptionsetText = GetOptionsetText(app, _service, "gits_herupwcwfs", gits_WorkflowStatus.Value); string remarks = "No Comments!"; if (gitsPluginEntity.Contains("gits_remarks")) remarks = (string)gitsPluginEntity["gits_remarks"]; string subject = prepareEmail(context, _service, app, tempusr, remarks); sendEmail(Webadmin, tempusr, GlobaloptionsetText, subject, app); //******************************** tempusr = loadBal(teamIT); ent = new Entity(gitsPluginEntity.LogicalName); ent["gits_statusreport"] = new OptionSetValue(449930031); ent["gits_herureviewfid"] = gitsPluginEntity["gits_herureviewfid"]; // ent["gits_nextuser"] = new EntityReference("systemuser", tempusr); if (gitsPluginEntity.Contains("gits_remarks")) ent["gits_remarks"] = gitsPluginEntity["gits_remarks"] + " \n \n Dear IT please creates accounts for the listed PMs in the review form"; _service.Create(ent); shareRecord(app, tempusr); GlobaloptionsetText = GetOptionsetText(app, _service, "gits_herupwcwfs", gits_WorkflowStatus.Value); remarks = "No Comments!"; if (gitsPluginEntity.Contains("gits_remarks")) remarks = (string)gitsPluginEntity["gits_remarks"]; subject = prepareEmail(context, _service, app, tempusr, remarks); sendEmail(Webadmin, tempusr, GlobaloptionsetText, subject, app); //*************************** string linkFromEntityName = "gits_heru_reviewer"; QueryExpression query = new QueryExpression(linkFromEntityName); query.ColumnSet = new ColumnSet("gits_name", "gits_heru_reviewerid"); LinkEntity linkEntity1 = new LinkEntity(linkFromEntityName, "gits_gits_heruinstrev_gits_heru_rev", "gits_heru_reviewerid", "gits_heru_reviewerid", JoinOperator.Inner); LinkEntity linkEntity2 = new LinkEntity("gits_gits_heruinstrev_gits_heru_rev", "gits_heruinstitutionalreview", "gits_heruinstitutionalreviewid", "gits_heruinstitutionalreviewid", JoinOperator.Inner); linkEntity1.LinkEntities.Add(linkEntity2); query.LinkEntities.Add(linkEntity1); linkEntity2.LinkCriteria = new FilterExpression(); linkEntity2.LinkCriteria.AddCondition(new ConditionExpression("gits_heruinstitutionalreviewid", ConditionOperator.Equal, app.Id)); query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0); EntityCollection collPhases = _service.RetrieveMultiple(query); Entity reviewerEntity = null; Entity conflictEntity = null; EntityReference HeruRevRef = new EntityReference("gits_heruinstitutionalreview", app.Id); EntityReference ReviewerRef = null; foreach (Entity PMs in collPhases.Entities) { if (PMs.Contains("gits_heru_reviewerid")) { reviewerEntity = _service.Retrieve("gits_heru_reviewer", new Guid(PMs["gits_heru_reviewerid"].ToString()), new ColumnSet(true)); } ReviewerRef = new EntityReference("gits_heru_reviewer", reviewerEntity.Id); QueryExpression queryConflict = new QueryExpression() { EntityName = "gits_heruconflictform", Criteria = new FilterExpression(LogicalOperator.And), ColumnSet = new ColumnSet("gits_reviewer") }; queryConflict.Criteria.AddCondition("gits_herureviewrefid", ConditionOperator.Equal, app.Id); queryConflict.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0); EntityCollection _coll = _service.RetrieveMultiple(queryConflict); bool thereisRecord = false; string str = null; foreach (Entity e in _coll.Entities) { conflictEntity = _service.Retrieve("gits_heruconflictform", new Guid(e.Id.ToString()), new ColumnSet(true)); if (conflictEntity.Contains("gits_reviewer")) { EntityReference confRevRef = new EntityReference(); confRevRef = (EntityReference)conflictEntity["gits_reviewer"]; if (confRevRef.Id == reviewerEntity.Id) thereisRecord = true; } if (thereisRecord == true) break; } conflictEntity = new Entity("gits_heruconflictform"); conflictEntity["gits_reviewer"] = ReviewerRef; conflictEntity["gits_university"] = app["gits_university"]; conflictEntity["gits_herureviewrefid"] = HeruRevRef; if (thereisRecord == false) _service.Create(conflictEntity); app["gits_testonly"] = str; _service.Update(app); //here is the error I think } app["gits_approvedpmsselecteddate"] = DateTime.Today; _service.Update(app); } break;

    Here is the error details:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Sequence contains more than one elementDetail:
    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
    <ErrorCode>-2147220891</ErrorCode>
    <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
    <KeyValuePairOfstringanyType>
    <d2p1:key>OperationStatus</d2p1:key>
    <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
    </ErrorDetails>
    <Message>Sequence contains more than one element</Message>
    <Timestamp>2016-03-13T08:50:38.2463944Z</Timestamp>
    <InnerFault i:nil="true" />
    <TraceText>

    [GITS.QAA.HeruRevPWC.Workflow: GITS.QAA.HeruRevPWC.Workflow.wodPlugin]
    [a5a3d38f-dd1d-e311-b96b-3640b5dee5db: GITS.QAA.HeruRevPWC.Workflow.wodPlugin: Create of gits_herupwcstatushistory]


    </TraceText>
    </OrganizationServiceFault>

    Thanks,

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi csHasan,

    Please try the below:

    First remove the field which you are updating from entity:

    app.Attribute.Remove("gits_testonly");

    app.Attribute.Add("gits_testonly",str);

    The same foe other filed

    app.Attribute.Remove("gits_approvedpmsselecteddate");

    app.Attribute.Add("gits_approvedpmsselecteddate",DateTime.Today);

    Hope this helps you :)

    Regards

    Hemant

  • Community Member Profile Picture
    on at

    Thanks, but still the same error

  • necsa Profile Picture
    3,455 on at

    Hi ccHasan,

    It looks like you need FirstOrDefault() in the query if your matching more than 1

  • Verified answer
    Community Member Profile Picture
    on at

    Thanks,

    It was nothing of previous.

    the Update statement in the code was triggering another plugin which causes the problem.

    I set the first plugin to run pre operation.

    I set the other plugin to run post operation and asynchronous and that resolved the issue.

    thanks,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans