- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2024 07:22 PM
we have a select box field with 1 to 10 choices when user select option 4 then 4 tasks should get created if i complete all four tasks then RITM state should complete if i incomplete the tasks then RITM state should be incomplete how can we achieved this using workflow can anyone please help me with the script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 12:53 AM
@Arun61 Please try to implement the use case in flow designer as per @Mark Manders.
But if you still require it using workflow, below is a snippet of achieving the use case.
1. Created a selected box variables with choices 1, 2, 3
2. Created a run script in workflow to create tasks dynamically
Dynamic tasks creation based on the variable value selected:
var length = current.variables.select_the_value;
for (var i = 0; i < length; i++) {
var task = new GlideRecord("sc_task");
task.initialize();
task.parent = current.sys_id;
task.short_description = "Catalog Task creation count : " +i;
task.request = current.request;
task.request_item = current.sys_id;
task.insert();
}
3. Wait until all the tasks are not active
checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.sys_id);
grTask.addQuery('active', true);
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}
4. Validate if all tasks are "Closed Complete" or "Closed Incomplete"
5. Set the RITM state accordingly
Note: This works only if the catalog task states are same. Incase of violation of states, it considers only the last updated record state.
Modify the scripts as per your requirement for the other fields.
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2024 11:35 PM
Why use workflow? Workflow is being replaced by flow designer and within the flow designer you can just drag and drop anything you need the flow to do.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 12:53 AM
@Arun61 Please try to implement the use case in flow designer as per @Mark Manders.
But if you still require it using workflow, below is a snippet of achieving the use case.
1. Created a selected box variables with choices 1, 2, 3
2. Created a run script in workflow to create tasks dynamically
Dynamic tasks creation based on the variable value selected:
var length = current.variables.select_the_value;
for (var i = 0; i < length; i++) {
var task = new GlideRecord("sc_task");
task.initialize();
task.parent = current.sys_id;
task.short_description = "Catalog Task creation count : " +i;
task.request = current.request;
task.request_item = current.sys_id;
task.insert();
}
3. Wait until all the tasks are not active
checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.sys_id);
grTask.addQuery('active', true);
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}
4. Validate if all tasks are "Closed Complete" or "Closed Incomplete"
5. Set the RITM state accordingly
Note: This works only if the catalog task states are same. Incase of violation of states, it considers only the last updated record state.
Modify the scripts as per your requirement for the other fields.
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.