How to use flow designer subflow to pull from the existing flows attachments

joshuacomeau
Tera Contributor

I have a record producer that has multiple unique attachment variable fields and upon submission it creates multiple unique child tasks and all attachments attach to the parent record. 

I am trying to figure out how to build a subflow / etc so that it will look up the attachments and based on specific variables they will copy to specific child tasks of the parent record.

 

I was thinking to look up the sys_attachment table by tablename but theirs no way to query the variablenames from this table.

 

If someone can provide steps/pictures on how this would look like in flow designer that would help a lot!

7 REPLIES 7

joshuacomeau
Tera Contributor

joshuacomeau_0-1737654920228.png

that is correct it is 1 to 1 mapping 

and please see attached the flow 

how would I add the logic you are mentioning 

with that being said would it be easier to use a business rule 

@joshuacomeau 

you can use after insert BR on that child table

Something like this in BR script

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var parentTableName = ''; // give the parent table name here
    var parentTaskRec = new GlideRecord(parentTableName);
    if (parentTaskRec.get(current.parent)) { // give the parent field name
        var type = current.technology_task_type.toString(); // give the correct field name here for task type
        // compare correct value here if it's choice field
       // give the correct respective variable name
        if (type == 'Architecture') {
            new global.VariableUtil().copyAttachment(parentTask.variables.variabel1, parentTableName, current.sys_id);
        } else if (type == 'TypeB') {
            new global.VariableUtil().copyAttachment(parentTask.variables.variabel2, parentTableName, current.sys_id);
        } else if (type == 'TypeC') {
            new global.VariableUtil().copyAttachment(parentTask.variables.variabel3, parentTableName, current.sys_id);
        }
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 
This looks exactly on track on what I am trying except on small condition/information:

Can you help with the code in terms of:

Example 1:

if the variable is called "attachmentArchitect" and they upload an attachment to the field.

when they submit the form

(copy attachment ONLY to task with assignment group architect)

 

Example 1:

if the variable is called "attachmentSecurity" and they upload an attachment to the field.

when they submit the form

(copy attachment ONLY to task with assignment group security)