How to copy a field from a subworkflow to a task created in the parent workflow?

James Cook
Tera Contributor

Hello all and thanks for the help, I have a task to copy a field from a sub workflow task to a task that is created in the parent workflow. Both tasks are on the same table (task) bellow is the client script that I have been trying to get to work. Thanks again for the help.

 
function onLoad() {
   var shortDesc = g_form.getValue("short_description");

    var gr = new GlideRecord("task"); //get parent change number of the first task
    gr.addQuery('sys_id', g_form.getValue('parent'));
    gr.query();


    while (gr.next()) {
        var saMig = g_form.getValue("u_sa_migration_file");
    }
   
    g_form.addInfoMessage('Short Desc = ' + shortDesc);
    g_form.addInfoMessage('sa migration = ' + saMig);
   
    if (shortDesc.startsWith('Migration Task - GIT WAR TASK') ||
        shortDesc.startsWith('Migration Task - GIT WAR TASK (Emergency)')){
   
        g_form.setValue("u_sa_migration_file",saMig);

    }
}
1 REPLY 1

Kai Tingey
Tera Guru

where is this script in the scheme of things? looks like a client script, which isn't going to work because you cant do a glide lookup in a client script. You'd need to use ajax.

 

if your script is in a workflow that runs on the child task, then you can just use this:

 

 

var shortDesc = current.short_description
var saMig = current.u_sa_migration_file;

var grpar = new GlideRecord('task'); //assuming it is in the task table, otherwise change to appropriate table
grpar.get(current.parent); //likewise change if field name of parent differs

if (shortDesc.indexOf('Migration Task - GIT WAR TASK') > -1){

	grpar.u_sa_migration_file = saMig;
	grpar.update();

}

 

if you're not committed to workflow editor just yet, it might be a good idea to migrate it to flow designer - then you could just use the breadcrumbs

 

if the script is outside of a workflow / flow - then you should consider a business rule