How to set conditions to avoid duplicate run for Tasks creation for a User Story - azure-devops

I created a Power Automate flow to create 9 tasks (Dev, Testing, and BA tasks) as a child for a new user story when it is assigned.
It works fine but it is getting duplicated every time when the story is assigned back from Unassigned to a resource.
I tried to get the count of related tasks for the user story before creating them but couldn't find any default conditions to get that.
Is there any other condition to set to avoid this duplicate task creations?

Solution for the query to set a condition to check for the existing workitems before creating them has been provided by yashag2255 on the Power Automate forums:
To get the work items related to the user story, you will have to send a HTTP request for that. But before sending this request -> Go to Azure DevOps -> Queries -> My Queries -> Create a new blank query and save it. (In this example let us say TestNew).
After you have done this, in the flow under the trigger create an action as shown. Very carefully populate all the fields. (here 'yashTest' is my project, replace it with yours)
Body : {
"name" : "TestNew",
"queryType" : "tree",
"wiql" : "SELECT [System.Id],[System.Title],[System.State] FROM workitemLinks WHERE([Source].[System.WorkItemType] = 'Task' AND [Source].[System.Id] = )AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')AND ([Target].[System.WorkItemType] = 'Task')MODE (Recursive)"
}
in the "wiql" near the [System.Id] = select the ID of the work item retrived from the trigger action (the original trigger request that has the id of the assigned work item)
Now, create a new string variable to get the query ID and put the foloowing expression in the expression editor and add it to the string value.
body('Send_an_HTTP_request_to_Azure_DevOps')['id']
Now add another action: Get Query Results with the query ID in the previous step. This will fetch you a list of the work items related to the assigned work item. You can iterate thorough this to check if the items exist and if not create them with Create Work Item Action.
Source: https://powerusers.microsoft.com/t5/Building-Flows/How-to-set-conditions-to-avoid-duplicate-Tasks-creation-for-a/td-p/289629

Related

Create query in Azure Devops server filtering on User Stories or tasks

I'm struggling to create a query to filter on either the parent user story or the nested child task but I can't figure out if this is possible.
For example:
There is a user story assigned to user A with tasks assigned to User B and C
There is another user story assigned to user C with tasks assigned to user A, B and C.
Is there a way to create a query which returns both of the user stories and all of their tasks when filtering on user A? I also like the hierarchy to be right, ie the user stories should contain tasks as links.
As a workaround, check the pic below:
Note: If the task assigned to user A, the parent-child relationship that returns the result is the opposite
Update1
We cannot get the result in the one query, we need to create different queries to get results.
Task assign to A
User Story assign to A.
Update2
Install the extension Query Based Boards->create query->save the query and click the tab Show as Taskboard, then we could see the result.

How to apply query / filter on a datasource related to the currently selected datasource?

Case:
I have 3 datamodels:
Tasks
Sub-Tasks
Status
The models are related in the following way: Tasks have a many-to-one with Statuses, same applies to Sub-Statuses. Some e.g. statuses are: To Do, Doing Done etc.
I can filter all Tasks using a dropdown with a set value of: "#datasource.query.filters." so that I select an option, only the records that have the specific value are shown.
I cannot use query on related datasources. E.g. if I want to apply query on "Tasks:Sub-Tasks(relation)", in order to filter the sub-tasks by their status (Sub-Tasks:Status(relation), query is missing as an option.
How can I achieve this? How can I apply a filter to related to the currently selected record items based on a specific to them attribute?
Case 2
How can a list based on multiple relationships be set up?
3 datasources:
Stages
Statuses
Tasks
Tasks pass through stages, with its status changing along the way as well. E.g. Task can be in planning stage with status to do, doing or done.
Please refer to the added screenshot for an interface example.
This is only one possible solution. But I would suggest the following:
Create 3 datasources within Tasks Model, SubTasksToDo,
SubTasksDoing, and SubTasksDone.
Within each datasource set the type to 'Query script' and add a
parameter (type string or number depending on what your task primary
key type is), call it 'MainTaskKey', and for each datasource uncheck
the autoload option.
For each datasource enter a query script of:
query.filters.YourMainTaskRelationEndName.id._equals = query.parameters.MainTaskKey;
query.filters.Status._equals = 'To Do'; //replace with 'Doing' or 'Done' depending on which datasource you're working in
Go to your Main Tasks datasource and scroll down finding the
onItemChange client script and enter the following in the code
block:
var itemKey = datasource.item.id;
var todo = app.datasources.SubTasksToDo;
var doing = app.datasources.SubTasksDoing;
var done = app.datasources.SubTasksDone;
todo.properties.MainTaskKey = itemKey;
doing.properties.MainTaskKey = itemKey;
done.properties.MainTaskKey = itemKey;
todo.load();
doing.load();
done.load();
Then go to your page an insert a panel for each of the 3 SubTask
datasources and put in a table or whatever you need.

Update sales order items using a workflow in NetSuite

I'm starting to get the hang of NetSuite but this one has stumped me. I am looking for a way to update the line items on an order from a workflow in NetSuite. From what I can tell it doesn't seem to expose those fields, is there any way around this?
I have a saved search returning all of the transaction line items that I want modified, there is a field on the Sales Order Line Item called "Create Fulfillment Order". It shows up under saved searches as "Create Fulfillment Order Column", but when I add an action to a workflow to set the field value, the only fields that show up are Sales Order fields. Is there any way to access the Sales Order Column fields, since that's really what's being returned by my saved search anyways.
I've looked at the Sub Types defined in the workflow to see if there's one for Sales Order Item or anything but there's not, just Sales Order. Any help would be greatly appreciated, thanks in advance!
There's nothing built-in that will let you access transaction line items from a workflow. You'll need to use SuiteScript to create a custom workflow action. Then you can call that action from your workflow.

Workflow to change order status if a custom field is populated for Sales Orders in NetSuite

Basically I want the orders to import under Pending Fulfillment only when the selected triggering client field has a value in it (any value). If it is blank I don't want this workflow to run on that SO. I have another workflow in place that affects other orders that are imported through Web Services, so this will be just for specific orders when the Triggering Client Field has a value. I set it up, as you can see in the images attached and no luck!
Parameters: Order Status=Pending Fulfillment (Static value)
Trigger on: After Field Sourcing
Contexts: Web Services
Triggering Client Fields: Custom free form text field that will be
populated with a 4-5 digit number
This looks like it will only work within the UI when someone is entering a sales order - and actually it won't work at all because if that's a free form text field, then it won't trigger the "After Field Sourcing" event. I would make the trigger Before Record Submit, or After Record Submit instead, and then under the "Condition" section, use the visual builder to tell set the criteria to only when Handshake Order ID is not empty. That should do the trick for you.
Please change your workflow action as below
Workflow Action : Import Status
Trigger On : Entry
Condition : {custbody11} is not null

Salesforce: trigger on related list

Suppose I have two objects
1.Account- standard object[it has a field name Status_c which is a picklist having value inprogress and closed]
2.Client_c - custom object[it also have same field name Status__c which is a picklist having value inprogress and closed]
and Client__c has lookup to Account name which means Account has a related list of client object .
My question is :
I want to write a trigger where if I put account status to "closed" I can not put client status to "closed",it should throw an error message on client object or if I put client status to closed I can not put account status to closed vice versa.
Can any one please help me to write a trigger on this??
Conceptually, I think what you are looking to do is set up Validation Rules on both of those objects. Your validation rule on Client_c should be pretty simple: TEXT(Status_c) == 'Closed' && TEXT(Account_c.Status_c) == 'Closed'
The more interesting piece is how you handle making sure none of your related items are Closed when you move the Account to Closed. I tend to prefer creating a field on the Account that keeps track of the status of the related items (checkbox) that basically tells me whether it is valid for me to change my status or not. In this case, the validation rule becomes pretty simple. In order to set that boolean value, I end up using a Trigger on Client__c that basically just grabs all the Accounts when a Client is being modified in the batch (taking into account both inserts, upserts, and deletes):
SELECT Account__c.Id FROM Client__c WHERE Id =: Trigger.new OR Id =: Trigger.old
Then create a Set of all the Account Ids (in this example, named accounts), and run a query to retrieve ALL Clients related to those Ids (in a single query to ensure you don't hit SOQL limits).
SELECT Account__c.Id, Status__c FROM Client__c WHERE Account__c.Id =: accounts
From the results of this, you will iterate over all of the entries, tossing them into a Map keyed by the Account Id where the value is a List of Clients. When you are done, run a query to get all accounts based on the "accounts" list from earlier (which was just a list of strings, not actual Accounts), subsequently iterate over all the Clients associated with that Account, and if a Client is marked as Closed, you will update the metadata of that Account accordingly. If no Clients are closed, the Account will be marked as such. Once you are finished, run an update statement to update the list of Accounts that you have modified.