Help with Flow designer code (autoassign "assigned to" field)

cicgordy
Tera Guru

Hi all,

 

I have a few subflows and I need to add a code in flow designer, within the "assigned to" field code snippet when creating a "catalog task action" (image below)

cicgordy_0-1677593757465.png

I need to auto-assign the same person that user would assign this particular task to, to subsequent tasks that creates after in other subflows(so perhaps by using short description name of other tasks).

So I guess I will need to add a code into subsequent tasks "assigned to fields" where I will need to copy same person assigned for previous task. 

Anyone can help in writing this code? 

 

Many thanks

1 ACCEPTED SOLUTION

Hi,

Yea, so have you went to your list view of RITMs and found the RITM you're testing with and double checked that it actually has an SCTASK associated to it with the short description as you're showing?

 

Just to add more to all this, I have now gone to the level of effort to build a flow and subflow in my own instance to this does work...

 

 

var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", fd_data.subflow_inputs.ritm.sys_id);
gr.addQuery("short_description", "Provide requested service");
gr.query();
if (gr.next()) {
  return gr.getValue("assigned_to");
}

 

So in my example script, my input was the RITM trigger record in the parent flow. Keep in mind that you need to test the subflow separately from testing the main flow. Otherwise, do a full execution of the flow in a real test (not a flow designer test) OR...ensure your subflow is Published, not just saved, and then run test from parent flow.

 

I'm starting to run out of options to assist further without asking that you start all over again with providing precisely what you have today with full screenshots and everything...which I hope we don't need to do. I know what I've provided is working.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

16 REPLIES 16

Allen Andreas
Administrator
Administrator

Hello,

If these tasks are sequential, meaning they aren't all issued at the same time, but instead one after the other and the flow waits for each one to finish/complete, then...after each create task action, you have access to those pills on the right-hand side. When creating tasks after the 1st, you can access those create task actions (so the settings/configuration for each) and drag the prior task's "assigned to" pill and set it to that new tasks assigned to field. All without code.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi @Allen Andreas

Yes thats right, I'd have done the same if I only had one flow.

Because I have different tasks in different subflows, I won't be able to drag the "assigned to" pill from a subflow to another, hence I thought I needed to code in each "assigned to" fields of the tasks needed.  

Hi,

My apologies that my reply wasn't helpful, I didn't see the subflow part in your script. If possible, feel free to add more information to your post in the future such as what you've tried thus far, etc. Just to help us help you.

 

Moving on...you'd want to use script then to query for related records and order them by their number (newest to oldest). Example of a GlideRecord query here: https://developer.servicenow.com/dev.do#!/reference/api/rome/server_legacy/c_GlideRecordAPI#r_GlideR... 

 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', 'request_item_value_here');
gr.orderByDesc('number');
gr.query();
if (gr.next()) {
return gr.assigned_to;
}

 

The above is just an example, but that is what you could use and you'd want to replace the "request_item_value_here" with the sys_id from the RITM record. So if you have access to that, you should, you can walk to it like: fd_data. and right after pressing the . you'll see the guide pop-up to help you walk to that RITM sys_id value.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@Allen Andreas is it possible to achieve this by querying the "short description name" of the tasks I want to auto-populate the "assign to"? Because not all the tasks are creating after another, I may have to skip some.