Trying to delete all records in a list based on a where clause - rest

All of my workflows for a site have the ability to log data in the Workflow History list on my site. This is controlled at run-time with a parameter in list based on the workflow Name. I would like to be able to run a workflow on this setup table that will delete all records in the History list. My understanding is I can do this via REST call in SharePoint Designer workflow.
I have attempted many times to configure the REST Post command in Designer and I am never able to get this to work. I've searched over and over for a solution and not able to find such a solution.
I first tried deleting all that had the Workflow Association ID equal to the Workflow Name, but could not get that to work. Then I thought I would try selection each value using REST and then deleting that value using REST by the ID I received from the GET.
This is my delete (POST).
[%Workflow Context:Current Site URL%]/_api/lists/GetByTitle('Workflow History')/GetItemObject('[%Variable: HistoryID%]')
I also tried the DeleteListItem
[%Workflow Context:Current Site URL%]/_api/lists/GetByTitle('Workflow History')/DeleteListItem('[%Variable: HistoryID%]')
I want the user to be able to run this on any workflow from the setupWorkflow list I have. The workflow should delete all history for the current workflow.

We can get the list items in Workflow History list base on the WorkflowInstance, in designer workflow, we can get the Instance ID from the Workflow Context.
/_api/web/lists/getbytitle('Workflow%20History')/items?$filter=WorkflowInstance eq 'b87b131e-ce22-43f5-85be-ec81d1045bc7'
Then delete list item using REST API below.
/_api/web/lists/getbytitle('Workflow%20History')/GetItemById(ID)
The following articles for your reference.
Using HTTP Call/ Rest API from SharePoint Designer workflow to create list
workflow to delete list item on subsite( Sharepoint designer call http web service )

Related

Insert value into Azure DevOps Custom Fields through Rest Api

I've added some custom fields for Test Plan in Azure DevOps. But when I try to create a new Test Plan through the Rest API call, it is only creating a Test Plan with default fields populated, while custom fields remain blank.
I've tried using both the field name (like Team Name) along with field reference name (like custom.TeamName) but to no avail. Even Get is also not exposing custom fields. Is some extra configuration required for custom fields, or it is a code related issue?
Details: I've created one Inherited process under the organization, and then under Process->Test Plan I've created new fields in the Test Plan, as shown in the screen shot:
I've tried below code to create Test Plan as Work Item and successfully created it with extra fields. But as I couldn't create a test suite independently, it is not behaving properly.
I've created a JsonPatchDocument and added all the fields (adding just one here) like below code:
JsonPatchDocument patchDocument= new JsonPatchDocument();
patchDocument.Add(
{
Operation=Operation.Add,
Path="/fields/System.TeamName",
Value="Xander"
}
);
VssConnection connection=new VssConnection(uri,credential);
WorkItemTrackingHttpClient workItemTrackingHttpClient= connection.GetClient<WorkItemTrackingHTTPClient>();
WorkItem res=workItemTrackingHTTPClient.CreateWorkItemAsync(patchDocument,project,"Test Plan").Result;
It is creating the Test Plan, but not Test Suite. So it is acting weirdly. Kindly check this.
Insert value into Azure DevOps Custom Fields through Rest Api
I could reproduce this issue with the REST API Test Plans - Create.
I think this should be related to the REST API, that because even if I use the REST API Test Plans - Get to get the custom field, but the request body does not include the custom field.
Since we could not get the custom field, we could not use the POST or PATCH for the custom filed.
You could add this request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.

How to get the associated changes, check-in comments and linked work items for a particular build/release in VSTS

I am using SendGrid email extension to trigger a custom email notification after the CI/CD process is complete in VSTS. This email task has HTML content in it which includes some content fetched using standard build/release variables (https://learn.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?tabs=batch).
How do I include associated code changes, check-in comments and linked work items for a particular release in the custom email? Are there any variables I can use? Any work around?
There aren’t the built-in variables that can get code changes, check-in comments and linked work items.
You can get them through REST API during build or release:
Get build changes and work items through Get Build Changes REST API (Build id variable: Build.BuildId during build or Release.Artifacts.{Artifact alias}.BuildId during release) Note: using Build.SourceVersion to get latest version)
Git: Get commit message through Get a batch of commits by a list of commit IDs REST API
TFVC: Get check-in comment through Get list of changesets by a list of IDS REST API
To get changed items, you can use get commit with changed items or Get list of changes in a changeset REST API.
No API to get detail code changes, but you may refer to this related issue: Lines of Code modified in each Commit in TFS rest api. How do i get?
Assuming TFS (which isn't specified in the question or tags), you could also call tf.exe directly to get some of that info. If you don't care about the output format, then the output of the following command produces a report of the Changeset details.
tf vc changeset <changeset id> /loginType:OAuth /login:.,<token> /noprompt
Where <changeset id> is the numeric Build.SourceVersion, and <token> is the System.AccessToken.
Comments and source code edits listing are included in the report.
Note: the agent job has to be given the "Allow scripts to access the OAuth token" permission (check box on the Agent Job properties).
See the updated link below for details on how to access the build variables. Same content as in the question, but new link. Both currently work.
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

how to get all the Task in a Workitem in Json form by postman for TFS API

i am currently using TFS API who's link is
https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#byids
currently in my project i want to accees the following workitem 61092 all the task
http://apactfs.cbre.com:8080/tfs/CBRE.APAC.Applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092
for that i am using this link in postman GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/workitems/61092?$expand=all&api-version=1.0
i am getting all the task related to it but not getting all the field such as number of hours in the task,user of the task which i wanted.
and in Postman i am hitting the id by this Link By GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092&api-version=1.0
According to your screenshot, 61092 is a Product Backlog Item. The Rest API URL you use can only get the detailed information of the work item 61092 itself, it cannot get the detailed information about the work items that linked to 61092.
You have to use One-hop Query to get all the tasks related to it and then get the detailed data for each task returned. Refer to this link for details: Get Work Items.
$expand=all has already expand all fields, but it doesn't show the empty fields in response. If you type a value for the field you want to get, you will see it as expect in response.

How to modify System.CreatedBy field in VSTS via API call

Apologies if this is very naive question. New to VSTS...
We are thinking to use VSTS for our daily project works. Currently, we are on old TFS hosted in-house. We have window application which is data entry tool and when any error generated Staff can raise support request via clicking one button which includes all traceback and any other necessary information for us to debug or they can raise new support work. We are thinking to integrate VSTS for our support work as well by calling API endpoint to create a task in VSTS.
I am thinking to use one service account in code that calls API to create a work item in VSTS however, I need to update System.CreatedBy field to the actual user rather than service account who raises this work item. I have seen numbers of other posts which says its read-only field.
The process is, I create a work item and then update CreatedBy field by calling following endpoint.
https://XXXXXX.visualstudio.com/DefaultCollection/_apis/wit/workitems/11?bypassRules=true&api-version=1.0
passing following JSON
[
{
"op": "replace",
"path": "/fields/System.CreatedBy",
"value": "Test, Mr <Test#example.com>"
},
]
This doesn't update the field.
Is there any way I can update this field? Thanks for your time.
Well, just read this https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/update?view=azure-devops-rest-6.0#update-a-link
NOTE: System.CreatedBy and System.CreatedDate can only be modified using bypass rules on work item creation, i.e. the first revision of a work item.

Implement Inbox Functionality in custom cq component?

We want to develop a smooth-flowing workflow experience (but still use workflows). Currently, a user needs to use the sidekick to initiate the workflow, then to the inbox, which takes them back to the page to use the sidekick again. When they go to the inbox, they need to restrict to the model and path of the page. It would be nice for the user to only have to go to the content page and from there, launch the different workflow forms that need to happen, like a little "inbox" right on the page that is subject to the workflow.
I have written a custom component that can initiate the custom workflow. The custom component can also query the WorkFlowSession and obtain any active WorkItems for the current page that the component resides (using the WorkItemFilter interface). What I want to do is provide a link to the user to the next step in the workflow from the custom component, just like the inbox does.
Here is an example output from an WorkItem instance toString method:
21.05.2014 09:45:29.300 *ERROR* [0:0:0:0:0:0:0:1%0 [1400679929160] GET /content/test/mailing1.html HTTP/1.1] org.rand.whatcounts.EmailCampaignCoordinator Found workitem: -----------------------------
WorkItem Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000/workItems/node4_etc_workflow_instances_2014-05-21_model_1400679794564399000
Workflow Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000
Payload: /content/test/mailing1
Payload Type: JCR_PATH
key = historyEntryPath value = /etc/workflow/instances/2014-05-21/model_1400679794564399000/history/1400679924113
key = comment value =
My hope is that by using the workflow api items, I can create the link that the user could click on to proceed in the workflow (just like the inbox).
Thanks for listening!
Phillip
There are two ways to implement this
Java-Based Solution
I was able to figure out one way by looking at
http://localhost:4502/libs/cq/workflow/components/inbox/list/json.jsp
The important part of this jsp is that, given a workItem instance, you can get the path for your next step using the JcrPathBuilderManager:
pathBuilder.getPath(wi);
Using this, I was able to output a link to the next step in the workflow to the user (without having user go to their inbox).
Javascript/JSON Based Solution
I didn't go far with this solution (I didn't write any js) but this was my fall back position if I didn't find the java-solution listed above. Once could implement custom JS in CQ Component that would call the json feed for the user inbox, do some client side filtering (to restrict it to only items related to current page). The URL to the feed is
http://localhost:4502/libs/cq/workflow/content/inbox/list.json?start=0&limit=40
Thanks!