Trying to set AssignedTo to in a Work item - azure-devops-rest-api

I am trying to set the AssignedTo in a PowerShell script, using the REST API.
The user already has a bunch of work items assigned, and has been in the system for several month.
I have tried using the Displayname, email (same as upn), and the link to the identity. All gives the same result:
Invoke-WebRequest : {"$id":"1","customProperties":{"ReferenceName":"System.AssignedTo"},"innerException":null,"message":"The identity value 'xxx#xxx.com' for field 'Assigned To' is an unknow
n identity.","typeName":"Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemFieldInvalidException, Microsoft.TeamFoundation.WorkItemTracking.Server","typeKey":"WorkItemFieldInvalidExce
I use the following script:
$tfsToken = "MYPAT"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($tfsToken)"))
$defaultColletion = "default_Collection"
$project = "Agile"
$childID = "63573"
$identityUpn = "xxx#xxx.com"
$childuri = ("http://tfs:8080/tfs/" + $defaultColletion + "/" + $project + "/_apis/wit/workitems?ids=" + $childID + "&expand=relations&api-version=5.0")
$header = #{authorization = "Basic $token"}
$childresult = Invoke-WebRequest -Uri $childuri -Method Get -Headers $header -ContentType "application/json-patch+json"
$childObj = $childresult.Content | ConvertFrom-Json
$updUrl = ($childObj.value.url + "?api-version=5.0")
$ownerUpd = #{}
$ownerUpd.Add("path","/fields/System.AssignedTo")
$ownerUpd.Add("op","add")
$ownerUpd.Add("value",$identityUpn)
$json = ConvertTo-Json #($ownerUpd) -Depth 5
$result = Invoke-WebRequest -Uri $updUrl -Headers $header -Method Patch -Body $json -ContentType "application/json-patch+json"

You can set into System.AssignedTo exactly what you see in Assigned To field in work item: Display Name of a user. You can find example here Update an identity field by display name:
[
{
"op": "add",
"path": "/fields/System.AssignedTo",
"value": "Jamal Hartnett"
}
]
Additional examples:
Update an identity field by distinct display name
Update an identity field by IdentityRef

That user already has work item assigned to him right?
So the first step in your case is to find what his unique name is under the AssignedTo field by using the below "Get Work Item Details API":
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=5.1
Then, use the same API you've used before but this time, provide the unique name value that you got from the previous API response.
[
{
"op": "add",
"path": "/fields/System.AssignedTo",
"value": "" # His unique name goes here
}
]
I would've commented this asking if you've tried using his unique name but I still dont have the sufficient points to post the comment.

If you have the Name and E-mail of the user you can use both in the format like when you send an e-mail. Example:
[
{
"op": "add",
"path": "/fields/System.AssignedTo",
"value": "user name <xxx#xxx.com>"
}
]

Related

Symfony form not working properly if a field is empty or not exists

To edit the entity training, I use the TrainingFormType like this:
public function editTraining(Training $training) {
$form = $this->createForm(TrainingFormType::class, $training);
$form->submit($request->request->all());
The form has a field title:
->add('title', TextType::class, [
'constraints' => [
new NotBlank(),
new Length(null, null, 50)
]])
If I pass in the request an empty value into the field title "title" : "", I get an error 500:
"Expected argument of type "string", "null" given at property path "title".". I expected here an error from the form, not the InvalidArgumentException
When using the same form for creating of a new training, everything works fine, a validation error is generated, as expected:
"title": {
"errors": [
"This value should not be blank."
]
},
It's how I use the form when creating a new training:
$training = new Training();
$form = $this->createForm(TrainingFormType::class, $training);
$form->submit($request->request->all());
How to solve this problem? I thought, I can resolve it using an so called IgnoreNonSubmittedFieldListener, but on this way it also doesn't work. I get the same error.
One possible solution is to set a sensible default in the Training entity for that field:
// in Training.php
// ORM mapping omitted:
private string _title = '';
Then when a new entity is created it will have that value.

How to indicate that the response body is a List in Swagger UI docs using FastAPI?

I describe the structure of the outgoing JSON in the model class, however I cannot make the output as a list.
My model class:
class versions_info(BaseModel):
""" List of versions """
version : str = Field(..., title="Version",example="2.1.1")
url : str = Field(..., title="Url",example="https://ocpi.wedwe.ww/ocpi/2.1.1/")
And in the documentation I see:
However, I need it to be displayed as:
[
{
"version": "2.1.1",
"url": "https://www.server.com/ocpi/2.1.1/"
},
{
"version": "2.2",
"url": "https://www.server.com/ocpi/2.2/"
}
]
What am I doing wrong?
You can indicate that you're returning a List by wrapping the response_model you've defined in List[<model>].
So in your case it'd be:
#app.get('/foo', response_model=List[versions_info])

Dynamic Filters for OData Read Based on Input

I have the requirement to send filter values via OData-service, to fill a table with relevant entries.
So basically there are input fields, where you can select e.g. "AA" (american airlines) for Carrier-ID.
So the filter values need to be created dynamically, regarding to the user input.
I tried following:
var aFilters = [
new sap.ui.model.Filter({
path: "Carrid",
operator: sap.ui.model.FilterOperator.EQ,
value1: "{selection>/Carrid}"
})
];
oModel.read("/SFLIGHTSSet",{
method: "GET",
filters: aFilters,
success: function(oData2, oResponse) {
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData({
modelData: oData2.results
});
oTable.setModel(oJSONModel);
oTable.bindRows("/modelData");
},
error: function(oError) {
console.log("Error!");
}
});
But that doesn't work.
I receive in back-end following request:
"( Carrid eq '{selection>/Carrid}' )"
So the binding doesn't work in the filter-creation...
The binding is correct because I can use it the same way in a Label:
new sap.m.Label({
text: "{selection>/Carrid}"
});
I researched a lot and know that people have problems with it in XML views.. but couldn't find any solution for JS-Views.
I guess your problem is in the line
"{selection>/Carrid}"
Get the value of the User-Input from the Control somehow like this
var sCarrid= this.byId("MySelection").getBindingContext("selection").getProperty("Carrid");
and modify your Filter
var oFilters = [ new sap.ui.model.Filter("Carrid",
sap.ui.model.FilterOperator.EQ,
sCarrid) ];

twillio - hot get the price of a number?

I need to get the price of each phone number, as it was in their "Buy a number" page https://www.twilio.com/user/account/phone-numbers/search
Variable $number do not contain such info.
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
"AreaCode" => "510"
));
foreach($numbers->available_phone_numbers as $number) {
echo $number->phone_number;
}
Ricky from Twilio here.
You can access pricing information using our Pricing API. This will let you query by country:
$client = new Pricing_Services_Twilio($AccountSid, $AuthToken);
$country = $client->phoneNumberCountries->get("US");
foreach ($country->phone_number_prices as $p) {
echo $p->number_type . " " . $p->current_price . "\n";
}
You can then use that information to properly assign the pricing with numbers you retrieve with the Available Phone Numbers API call.

Adding new Mantis status but ran out of enumeration values

I was wondering if you had any thoughts about this issue: We want to add one more status at a specific 'place' between two statuses, but we ran out of enumeration for it.
The enumeration looks like this:
$s_status_enum_string = "10:new,20:feedback,40:confirmed,50:assigned,52:in progress,53:code review pending,54:merge pending, 56:merged, 58:resolved, 60:testing, 70:tested, 90:closed, 91:updating test documentation";
And I want to add a new status between 52 and 53 so that, on the pull-down menu for status, they appear in the desired order.
I tried different things - including changing the .php file definitions then updating the MySQL table's status field in mantis_bug_table, but it messes up all the views and filters.
Any ideas?
The following steps might help you:
Redefine the enumeration string as per your requirements
Prepare a traceability with your current enumeration values
Update the status field in bugs table with the new values
Add the enumeration in config.php
You may have to reset your previous filters. The filter criteria is stored as a serialized string and it's very difficult to modify.
If anyone is having issues with this you need to change the following:
In config_inc.php modify $g_status_enum_string to ennumerate the new statuses as you see fit.
In custom_constants_inc.php make sure to do the same as above.
In the database, run SQL commands such as this:
UPDATE mantisclone.mantis_bug_table SET status=100 WHERE status=10;
to change the actual records for existing status IDs to new ones.
In custom_strings_inc.php modify $s_status_enum_string and input your new statuses. For example one of mine was:
$s_sanity_test_bug_title = "Set Issue Sanity Test";
$s_sanity_test_bug_button = "Issue Sanity Test Pending";
$s_email_notification_title_for_sanity_test = "The following issue is NOW SANITY TEST PENDING";
Finally you'll need a small script to change the existing ennumerated values in mantis_filters_table. This was mine, alter it as you see fit:
<?php
$mantisDB="myMantisDatabaseName";
mysql_connect("localhost", "XXXX", "YYYY") or die("Could not connect: " . mysql_error());
mysql_select_db($mantisDB);
$result = mysql_query("SELECT id, filter_string FROM $mantisDB.mantis_filters_table");
function parseRecord($statusArray)
{
$newStatus = array( "10" => "100",
"20" => "200",
"50" => "300",
"52" => "400",
"53" => "500",
"54" => "540",
"56" => "560",
"58" => "580",
"60" => "600",
"70" => "700",
"75" => "450",
"90" => "900",
"91" => "910"
);
foreach ($statusArray as $key=>$value)
{
if(array_key_exists($value, $newStatus))
{
echo "Found value $value, replacing it with " . $newStatus[$value] . "\n";
$statusArray[$key] = (int)$newStatus[$value];
}
}
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$statusID = $row["id"];
$serializedString = $row["filter_string"];
$unserializedArray = unserialize(substr($serializedString,3)); // There's a prepended 'v8#' string in there, don't know why.
parseRecord(&$unserializedArray["hide_status"]);
parseRecord(&$unserializedArray["show_status"]);
$newSerialized = "v8#".serialize($unserializedArray);
// echo $newSerialized;
$changeStatus = mysql_query("UPDATE $mantisDB.mantis_filters_table SET filter_string='$newSerialized' WHERE id=$statusID");
}
mysql_free_result($result);
?>
I hope this works, let me know if you're having any issues.

Resources