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
73 stars 32 forks source link

How can we set list value from rule. #277

Closed rbhole closed 1 year ago

rbhole commented 1 year ago

Hi,
I have 3 List fields Risk Probability (RP), Risk Impact(RI), and Risk Severity(RS). Based on the option selected from RP and RI then RS should calculate and set the value from the rule. My code as below, RP, RI, and RS all fields datatype are the Picklist (string).

String riskProbability = self["Custom.RiskProbability"]?.ToString();
    String riskImpact = self["Custom.RiskImpact"]?.ToString();
    String rP = riskProbability.Substring(0,1);
    String rI =  riskImpact.Substring(0,1);

    int selectedRiskProbability = Int32.Parse(rP);
    int selectedRiskImpact = Int32.Parse(rI);
    int severityIndex = selectedRiskProbability * selectedRiskImpact;
    String riskSevrity = "1 - 5 (Low)";
    if(severityIndex >= 6 && severityIndex <= 12){
        riskSevrity = "6 - 12 (Medium)";
    }else if(severityIndex >= 13 && severityIndex <= 25){
        riskSevrity = "13 - 25 (High)";
    }
    parent["Custom.RiskSeverity"] = riskSevrity;

After deploying the rule, I got the error as below,

[{"op":5,"Path":"/rev","From":null,"Value":14},{"op":2,"Path":"/fields/Custom.RiskSeverity","From":null,"Value":"13 - 25 (High)"}]

[{"Code":400,"Headers":{"Content-Type":"application/json; charset=utf-8"},"Body":"{\"fieldReferenceName\":null,\"fieldStatusFlags\":\"none\",\"errorMessage\":\"The field 'Risk Severity' contains the value '13 - 25 (High)' that is not in the list of supported values\",\"fieldStatusCode\":0,\"ruleValidationErrors\":[{\"fieldReferenceName\":\"Custom.RiskSeverity\",\"fieldStatusFlags\":\"hasValues, limitedToValues, allowsOldValue, invalidListValue\",\"errorMessage\":\"The field 'Risk Severity' contains the value '13 - 25 (High)' that is not in the list of supported values\",\"fieldStatusCode\":4194380,\"ruleValidationErrors\":null}]}"}]

Save failed: {"fieldReferenceName":null,"fieldStatusFlags":"none","errorMessage":"The field 'Risk Severity' contains the value '13 - 25 (High)' that is not in the list of supported values","fieldStatusCode":0,"ruleValidationErrors":[{"fieldReferenceName":"Custom.RiskSeverity","fieldStatusFlags":"hasValues, limitedToValues, allowsOldValue, invalidListValue","errorMessage":"The field 'Risk Severity' contains the value '13 - 25 (High)' that is not in the list of supported values","fieldStatusCode":4194380,"ruleValidationErrors":null}]}

So how can I set the list value to the RS field?

giuliov commented 1 year ago

The error is coming from Azure DevOps not from Aggregator. The field 'Risk Severity' contains the value '13 - 25 (High)' that is not in the list of supported values means that the Custom.RiskSeverity fielkd does not accept a generic string value: the value must be selected from the list of allowed values. The allowed values are set in the field definition: look in your Project Settings.

rbhole commented 1 year ago

Thanks @giuliov