tfsaggregator / aggregator-cli

A new version of Aggregator aiming at Azure DevOps (ex Visual Studio Team Services)
https://tfsaggregator.github.io/
Apache License 2.0
74 stars 32 forks source link

Question : Intermediate save #208

Closed ghost closed 2 years ago

ghost commented 4 years ago

I try migrate rule from the old Aggregator plugin. This rule aggregate effort from children to parent.

When a item has children, the effort fields is read only by custom Hosted XML process rule (fields["MyOrg.HasChildren"] == "true").

The Aggregator rule is 3 step 1) Set the field "MyOrg.HasChildren" to empty 2) Set effort value 3) Set the field "MyOrg.HasChildren" to true

This is the old rule :

//Step 1
parent["MyOrg.HasChildren"] = string.Empty; //Disable readonly on effort fields
//Step 2
parent["Microsoft.VSTS.Scheduling.CompletedWork"] = parent.Children.Sum(task => task.GetField<double>("Microsoft.VSTS.Scheduling.CompletedWork", 0d));
parent["Microsoft.VSTS.Scheduling.RemainingWork"] = parent.Children.Sum(task => task.GetField<double>("Microsoft.VSTS.Scheduling.RemainingWork", 0d));
parent["Microsoft.VSTS.Scheduling.OriginalEstimate"] = parent.Children.Sum(task => task.GetField<double>("Microsoft.VSTS.Scheduling.OriginalEstimate", 0d));
//Step 3
parent["MyOrg.HasChildren"] = parent.Children.Any().ToString(); // Enable readonly on effort fields

I write this rule to Aggregator CLI :

//Step 1
parent["MyOrg.HasChildren"] = "";
//Step 2
parent["Microsoft.VSTS.Scheduling.CompletedWork"] = parent.Children.Sum(c => c.GetFieldValue<double>("Microsoft.VSTS.Scheduling.CompletedWork", 0d));
parent["Microsoft.VSTS.Scheduling.RemainingWork"] = parent.Children.Sum(c => c.GetFieldValue<double>("Microsoft.VSTS.Scheduling.RemainingWork", 0d));
parent["Microsoft.VSTS.Scheduling.OriginalEstimate"] = parent.Children.Sum(c => c.GetFieldValue<double>("Microsoft.VSTS.Scheduling.OriginalEstimate", 0d));
//Step 3
parent["MyOrg.HasChildren"] = parent.Children.Any(c => !c.IsDeleted).ToString();

But this get the error :

Save failed: {
    "fieldReferenceName": null,
    "fieldStatusFlags": "none",
    "errorMessage": "TF401320: erreur de règle pour le champ Travail restant. Code d'erreur : ReadOnly, InvalidNotOldValue. 2 erreurs supplémentaires se sont produites durant la validation de l'élément de travail. Corrigez toutes les erreurs, puis réessayez.",
    "fieldStatusCode": 0,
    "ruleValidationErrors": [
        {
            "fieldReferenceName": "Microsoft.VSTS.Scheduling.RemainingWork",
            "fieldStatusFlags": "readOnly, invalidNotOldValue",
            "errorMessage": "TF401320: erreur de règle pour le champ Travail restant. Code d'erreur : ReadOnly, InvalidNotOldValue.",
            "fieldStatusCode": 16777218,
            "ruleValidationErrors": null
        },
        ...
        Same for Microsoft.VSTS.Scheduling.OriginalEstimate and Microsoft.VSTS.Scheduling.CompletedWork
}

I think Aggragator CLI send all values in one query. It's possible to do intermediate save in rule?

giuliov commented 3 years ago

Sorry for the delay. Well the SaveChanges method is public and can be called, but it would be my second choice. In fact it isn't documented.

My first choice would be to set the bypassRules flag except that you cannot set it independently but it is tied to the impersonate directive. It is not a complex change but I do not have time at the moment, so if you can submit a PR, I would be grateful... or be patient.

giuliov commented 2 years ago

Tracking this in #255