Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we update same field twice in a function... #88

Closed
KamranAslamBhatti opened this issue Dec 11, 2019 · 4 comments
Closed

Can we update same field twice in a function... #88

KamranAslamBhatti opened this issue Dec 11, 2019 · 4 comments
Assignees
Labels
bug Something isn't working fixed Bug got fixed or found a solution

Comments

@KamranAslamBhatti
Copy link

KamranAslamBhatti commented Dec 11, 2019

Hi,
I have one single function which is mapped to update event, now in that function I have two separate code sections which both updates to same field i.e. TargetDate. When this function runs it gives me following error:
An item with same key has already been added.

I also try to create two different function on update event and these both function updating the same field on some conditions but this also did not work, out of two only one function runs and other function gives 404 Not found error.

Here is my code which I am using in a single function to update same field and getting An item with same key already been added error.
Is there a way to update same field twice in a same function?

//1) Logic 1
//**********

var childrens = self.Children;
if (childrens != null)
{
 foreach (var child in self.Children)
 {
  var childDate =child["Microsoft.VSTS.Scheduling.TargetDate"]?.ToString() ?? DateTime.Now.ToString("u");
  child["Microsoft.VSTS.Scheduling.TargetDate"]=DateTime.Parse(childDate.ToString()).AddDays(2);
 }
}
//2) Logic 2
************
var allWorkItemLinks = self.RelationLinks;
if (allWorkItemLinks != null)
{
foreach(var successorLink in allWorkItemLinks.Where(link => string.Equals("System.LinkTypes.Dependency-Forward", link.Rel)))
{
   var id = int.Parse(successorLink.Url.Split('/').Last());
   var successor = store.GetWorkItem(id);
   var successorDate =DateTime.Parse(successor["Microsoft.VSTS.Scheduling.TargetDate"]?.ToString() ?? DateTime.Now.ToString("u"));
   successor["Microsoft.VSTS.Scheduling.TargetDate"]=DateTime.Parse(successorDate.ToString()).AddDays(2);
}
}

Thanks,
Kamran

@giuliov
Copy link
Member

giuliov commented Dec 12, 2019

Sounds like a bug, but need to investigate.
I guess you have a workitem linked both as a child and as a successor.

@giuliov giuliov added bug Something isn't working pinned Stops stale[bot] from closing this issue labels Dec 12, 2019
@BobSilent
Copy link
Collaborator

BobSilent commented Dec 12, 2019

Do you have a little bit more log context information about the error An item with same key already been added

I have an idea, i think it is returned from Server not (directly) from our Code. Sure the error is at our side.

@giuliov giuliov added the waiting issuer Waiting information or data from original issuer label Dec 26, 2019
@BobSilent BobSilent self-assigned this Dec 29, 2019
@BobSilent
Copy link
Collaborator

I tested a little bit around, there are two issues in code

  1. An item with same key already been addedAn item with same key already been added
    Occurs when a field not yet assigned (without value yet) in work item will be assigned twice

  2. You cannot update the same field will occurs from server, if you update a field twice, which already had a value in received work item (e.g. title)

I am over it to create a fix

@BobSilent BobSilent removed the waiting issuer Waiting information or data from original issuer label Dec 30, 2019
giuliov added a commit that referenced this issue Jul 28, 2020
error An item with same key already been added
giuliov added a commit that referenced this issue Jul 31, 2020
error An item with same key already been added
giuliov added a commit that referenced this issue Jul 31, 2020
* Address issue #88

error An item with same key already been added

* Logoff command

* Logon using Environment variables

* Logoff ruins the cleanup job
giuliov added a commit that referenced this issue Jul 31, 2020
* Address issue #88

error An item with same key already been added

* Logoff command

* Logon using Environment variables

* Logoff ruins the cleanup job

* Telemetry foundation

* ideas in progress

* telemetry session and anonymization

* general tracking in base classes

* finished Telemetry

unit testing, marked data sources, terraform
@giuliov
Copy link
Member

giuliov commented Aug 6, 2020

Fixed in 0.9.14

@giuliov giuliov closed this as completed Aug 6, 2020
@giuliov giuliov added fixed Bug got fixed or found a solution and removed pinned Stops stale[bot] from closing this issue labels Aug 6, 2020
@giuliov giuliov mentioned this issue Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Bug got fixed or found a solution
Projects
None yet
Development

No branches or pull requests

3 participants