Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scripting Issue: SCTask Flow Email is not generating a complete description

SusanSchwar
Tera Contributor

I created a script for a multirow variable set. For each row in the request, it should populate in the description of the task and the system generated email should display the complete description of the task. However, say the user request two rows: Job 1 and Job2, Each with their respective fields. Job 1, the first row, will populate. But any other row added to the table will not generate in the body of the email. Please let me know what I need to change to make this work. 

(function execute(inputs){
var item_id = inputs.ritm;
//gs.log("MRVS item id " + item_id);
var ritmGR = new GlideRecord('sc_req_item');
if(ritmGR.get(item_id)){
    gs.log("MRVS get item " + ritmGR.number);
    var mrvs = ritmGR.variables.request_details;
    //gs.log("MRVS length " + mrvs.getRowCount());
} else {
    //gs.log("MRVS item not found");
}
var gr = new GlideRecord("sc_task");

    gr.initialize();
    gr.request = ritmGR.request;
    gr.request_item = ritmGR.sys_id;
    gr.priority = 4;
    // we need a glide record to lookup the assignment group and the state needs to be set
    var grGroup = new GlideRecord("sys_user_group");
    grGroup.addQuery("name", "*team name");
    grGroup.query();
    if(grGroup.next()){
        gr.assignment_group = grGroup.sys_id;
    }
    gr.state = 1;
    gr.short_description = "Run Job Name:"; 
    gr.description = "Run the Job names listed in the details below. \n";
    gr.description += "Run date: " + ritmGR.variables.run_start_date + "\n";
    gr.description += "Run time: " + ritmGR.variables.run_time + "\n";
    gr.short_description += " " + mrvs[0].job_group_name;
for(var row = 0; row < mrvs.getRowCount(); row++) {
    //gs.log("MRVS row " + row);
    if (row ==0){ 
    gr.description += "\nJob name: " + mrvs[row].job_group_name; 
    if(mrvs[row].input_file_path){
        gr.description += "\nInput file path: " + mrvs[row].input_file_path;
    } else {
        gr.description += "\nInput file path: none";
    }
    if(mrvs[row].predecessor){
        gr.description += "\nPredecessor: " + mrvs[row].predecessor;
    } else {
        gr.description += "\nPredecessor: none";
    }
    if(mrvs[row].successor){
        gr.description += "\nSuccessor: " + mrvs[row].successor;
    } else {
        gr.description += "\nSuccessor: none";
    }
     if(mrvs[row].parameters){
        gr.description += "\nParameters: " + mrvs[row].parameters;
    } else {
        gr.description += "\nParameters: none";
    }
    if(mrvs[row].special_instructions){
        gr.description += "\nSpecial instructions: " + mrvs[row].special_instructions + "\n\n";
    } else {
        gr.description += "\nSpecial instructions: none\n\n";
    }

}
}
gr.insert();
})(inputs);
5 REPLIES 5

@SusanSchwar 

why you are using script to create catalog task?

Why not use "Create Catalog Task" flow action?

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