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

Hi,

Yes, you can query it any number of ways, just ensure that you're also filtering it for records that are related to the parent record involved in all this. So adding to the above:

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', 'request_item_value_here');
gr.addQuery('short_description', 'Exact Short Description Here');
gr.query();
if (gr.next()) {
return gr.assigned_to;
}

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

Hi @Allen Andreas,

I tried to put the code you provided above in the flow designer "assigned to" field code snippet of the task "IT stock" I am creating but isnt working. I replaced item sys ID with "requested_item_value" and added the short description name of the task I want to copy "the assigned to" from.

cicgordy_1-1677674507834.png

So, I want to copy and autoassign "the assigned to" of the "hardware check task"  into the "IT stock task"(in this action I added the code in the "assigned to" code snipped

 

Thanks

 

 

Hello,

The request_item_value meant the sys_id of the RITM. Please use that.

What you have now doesn't seem to be a sys_id.

Please use the value of the RITM sys_id as provided in your flow wherever that may be. We can't see your pills as none of your screenshots have them and if these are subflows, are you carrying any of the parent flow (such as the RITM information) down to the subflows as inputs, etc. If so, please use that as appropriate.


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

Hi @Allen Andreas

Apologise, I had deleted the actual sys ID as mistake and added a few characters just to take the screenshot, I did try with the actual sys ID of the item but didn't work. (see image below)

cicgordy_2-1677686078173.png

 

 

and yes in my subflows, I am carrying the parent flow by adding RITM input in all the others subflow. 

So really not sure why isnt updating the same assigned to in the next task!

cicgordy_3-1677686191439.png

 

 

 

Hi,

Ok, thanks for clarifying 🙂

For the return line, let's try and return string back. In my original script I had it returning the gliderecord object element for the assigned_to, you've changed it to be something else. Keep in mind that what we are returning...is what is being set in that field. So with your attempt of gr.assigned_to = current.assigned_to, that won't work.

 

Please try what I had provided earlier, but let's convert it to string such as:

 

 

return gr.getValue('assigned_to');

or you could use:

return gr.assigned_to.toString();

 


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