I have a work item in Azure DevOps Boards with "System.WorkItemType": "Template" and "System.Title": "Sample" and I need to retrieve the workitem details using rest api.
In the Azure DevOps, work item ID a unique identifier and we can create multiple work items with the same name.
As a workaround, we could run the wiql query to get workitems based on Title, then get the work item ID and list the work item details. You could check below script.
In my script, I listed the details of all work items whose title is test and work item type is User Story.
$connectionToken="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$WorkItemQueryURL = "https://dev.azure.com/{Org name}/{Project name}/{team name}/_apis/wit/wiql?api-version=6.0"
$body =#"
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.TeamProject] = #project and [System.WorkItemType] = 'User Story' AND [System.Title] = 'test' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
"#
$WorkItem = Invoke-RestMethod -Uri $WorkItemQueryURL -ContentType "application/json" -Body $body -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST
Write-host $WorkItem.workItems.id
ForEach ($ID in $WorkItem.workItems.id)
{
$WorkItemInfoURL = "https://dev.azure.com/{Org name}/{Project name}/_apis/wit/workitems/$($ID)?api-version=6.1-preview.3"
Invoke-RestMethod -Uri $WorkItemInfoURL -Headers #{authorization = "Basic $base64AuthInfo"} -Method Get
}
Result:
and Azure DevOps query result:
Related
I want to disable form fields in the update context, see the image:
I tried this, but it did not work
public function filterFields($fields, $context = null)
{
if($context == 'update') {
$fields->books->disabled = true;
$fields->user->disabled = true;
}
}
Seems you are trying to make relation manager field disable(read only)
But I am sure they are not following same pattern as normal widgets do.
they can not be disabled directly like that as I found another easy way.
you may have used partial for rendering this relational field ( book | user ) and your partial _books.htm is looking like this.
<?= $this->relationRender('comments', ['readOnly' => false]) ?>
You need to change it with this one
<?php if($this->widget->form->context == 'update'): ?>
<?= $this->relationRender('comments', ['readOnly' => true]) ?>
<?php else: ?>
<?= $this->relationRender('comments', ['readOnly' => false]) ?>
<?php endif; ?>
The magic config value is this readOnly property it will make list read-only or active working.
try this it will work , if not please comment.
I'm new to ZF2 and I'm willing to share how I do to retain parameter from form using url helper especially during pagination. I modify the answer from How can you add query parameters in the ZF2 url view helper
This is what I do:
AlbumController.php
// get all the query from url
$input = $form->getData();
$paginator = $this->getAlbumTable()->fetchAll();
$paginator->setCurrentPageNumber((int)$this->params()->fromQuery('page', 1));
$paginator->setItemCountPerPage(30);
// unset the 'page' query if necessary
unset($input['page']);
return array(
'form' => $form,
'paginator' => $paginator,
'routeParams' => array_filter($input) // filter empty value
);
index.phtml
echo $this->paginationControl(
$this->paginator,
'sliding',
array('partial/paginator.phtml', 'Album'),
array(
'route' => 'album',
'routeParams' => $routeParams
)
);
paginator.phtml
<a href="<?php echo $this->url(
$this->route, // your route name
array(), // any url options, e.g action
array('query' => $this->routeParams) // your query params
);
echo (empty($this->routeParams))? '?' : '&'; ?>
page=<?php echo $this->next; ?>">Next Page</a>
Please provide any better solution and correct me if I'm wrong.
Thank you
I don't have a much better solution than yours - I don't see a proper way to retain existing query params while adding some new ones. But the following is neater than manually appending & and = characters:
paginator.phtml
<a href="<?php echo $this->url(
$this->route, // your route name
array(), // any url options, e.g action
// Merge the array with your new value(s)
array('query' => array('page' => $this->next) + $this->routeParams)
); ?>">Next Page</a>
This will also ensure that if you already have a page param, it will be overwritten by the new one.
(Technically you could also use $_GET or $_POST directly and avoid passing it from the controller at all, but that doesn't seem very neat)
I generated the module "picture" and now I'm trying to call the action
"delete" this way:
frontend_dev.php/picture/delete/id/1
But I get this error:
500 | Internal Server Error | sfValidatorErrorSchema
_csrf_token [Required.]
stack trace at () in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/
sfValidatorSchema.class.php line 110 ...
$clean = array();
$unused = array_keys($this->fields);
$errorSchema = new sfValidatorErrorSchema($this);
// check that post_max_size has not been reached
if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > $this-
getBytes(ini_get('post_max_size')))
at sfValidatorSchema->doClean(array('_csrf_token' => null)) in
SF_ROOT_DIR/lib/vendor/symfony/lib/validator/
sfValidatorSchema.class.php line 90 ... */
public function clean($values)
{
return $this->doClean($values);
}
/** at sfValidatorSchema->clean(array('_csrf_token' => null)) in
SF_ROOT_DIR/lib/vendor/symfony/lib/form/sfForm.class.php line 247 ...
Any idea?
Regards
Javi
sf 1.4
I would highly recommend AGAINST commenting out the CSRF protection as suggested by dxb. Because then anyone will be able to access that deletion url and delete stuff from your database. Even if you limit the route to post methods, anyone familiar with Symfony can use the url to delete stuff from your database.
I am willing to bet the problem is with your link that goes to the delete url. In your template, if you create a basic HTML link/anchor like this:
<a href="www.mysite.com/frontend_dev.php/picture/delete/id/1>click me</a>
Then a _csrf_token is not generated and is not being passed. But if you generate a link using Symfony's helpers like this:
<?php echo link_to('click me', 'picture/delete?id=1') ?>
Then the link will be generated along with some javascript that inserts a hidden input field called _csrf_token. This method will correctly pass the CSRF token to the delete action and you will be protecting yourself.
The CSRF protection is there to protect you. Learning how to use it properly is always better than commenting it out and disregarding it.
You should use Symfony 1.4's built-in ability to generate a "Delete" link which uses JavaScript to perform a legitimate POST request to your delete route and passes along a valid CSRF token.
The following example assumes you have a route called file_delete which accepts a parameter id that is a number:
// apps/frontend/config/routing.yml
file_delete:
url: /file/:id/delete
param: { module: file, action: delete }
requirements:
id: \d+
Generate a "Delete" link that properly does a POST and adds a CSRF token:
<?php
echo link_to('Delete', 'file_delete', array(
'id' => $file->getId(),
), array(
'method' => 'delete',
'confirm' => 'Are you sure you want to delete this file?',
));
?>
While the above code works, I found a bug that still exists as of Symfony 1.4.18 that can result in the you seeing _csrf_token [Required.] after clicking the Delete link. This is due to Symfony generating JavaScript with a syntax error in it if passing an apostrophe into the confirm option (e.g. Are you sure you're ready to proceed?). To confirm the JavaScript syntax error is the culprit, open your browser's Console and click the link, then watch for an error to display quickly before it redirects. In my case it was easy to remove the apostrophe from the confirm text which fixed the issue.
If you call delete action through "Delete" button in form or list, then you can try to update buggy function _method_javascript_function() in UrlHelper.php to this version
function _method_javascript_function($method)
{
$function = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;";
$varFlag = false;
if ('post' != strtolower($method))
{
$varFlag = true;
$function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); ";
$function .= sprintf("m.setAttribute('name', 'sf_method'); m.setAttribute('value', '%s'); f.appendChild(m);", strtolower($method));
}
// CSRF protection
$form = new BaseForm();
if ($form->isCSRFProtected())
{
$function .= ($varFlag ? '' : 'var ')."m = document.createElement('input'); m.setAttribute('type', 'hidden'); ";
$function .= sprintf("m.setAttribute('name', '%s'); m.setAttribute('value', '%s'); f.appendChild(m);", $form->getCSRFFieldName(), $form->getCSRFToken());
}
$function .= "f.submit();";
return $function;
}
I have a list of Plants and assosiated Projects. I want to output this in a table with all the Plants and use Telerik.Grid to expand a Plant, show a Telerik.Grid with associated Projects. I want the Projects to be dynamically loaded with Ajax.
The code for the grid:
#(Html.Telerik().Grid<PlantDto>()
.Name("Plants")
.Columns(columns =>
{
columns.Bound(plant => plant.Title);
})
.DetailView(details => details.ClientTemplate(
Html.Telerik().Grid<ProjectDto>()
.Name("Plant_<#= Id #>")
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("ProjectsForPlant", "User", new { plantId = "<#= Id #>" }))
.ToHtmlString()
))
.DataBinding(dataBinding => dataBinding.Ajax().Select("PlantsForUser", "User"))
)
The initial data is loaded into the grid just fine (the list of Plants) but when I expand a plant I just get an empty sub-table.
Looking in FireBug there are no calls to the server. The controller that should serve the list of projects is never called.
Anyone have an idea on what it could be?
Update: Looks like what was causing trouble was that the plant.id had an "$" in it. Like "PCD$ODIN". Looks like that made life difficult for the JavaScript.
I compared your configuration to the one here and it looks identical. Test whether this Select method:
.Select("ProjectsForPlant", "User", new { plantId = "<#= Id #>" }))
set the plant id properly and if you need to name it exactly the same as the Id field instead of plantId, i.e.:
.Select("ProjectsForPlant", "User", new { Id = "<#= Id #>" }))
has someone make ajax.actionlink for delete to work properly.After deleting the record successfully at the end it is not refreshing the page properly. the page refresh is my problem. i have defined the updatetarget id and returning view(model) from my controller but it is returning the master page with it.
So the thing is that i am having a page with a page.I have used redirect as well which is not refreshing,
<%= Ajax.ActionLink("Delete", "Delete", new { id = item.int_OrganizationGroupId }, new AjaxOptions { UpdateTargetId = "abc", HttpMethod = "Post", Confirm = "Delete Group with Organization Group ID:" + item.int_OrganizationGroupId + " Organization Group Name:" + item.vcr_OrganizationGroupName, OnSuccess = "handleSuccess" })%>|
abc is the id of the table
From controller
View("ManageGroup,Model);
To use AJAX returns on models and views, you need to create a partial view and return that instead of a full view which will include your master page, etc.
Public Function AjaxView() as ActionResult
Return PartialView("NameOfYourPartialView", ItemsToReturn)
End Function