Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Triggering a notification containing requested item variables from flow designer

sjjantz
Tera Expert

I am trying to trigger an email notification from flow designer that contains all of the variables in a requested item. I was able to get the notification to populate the variables using the following script and using the sc_task table, but the workflow throws an error "Notification requires table sc_task, record is of type sc_req_item". If I change the table to sc_req_item, it does not pull the variables into the notification. Can somebody help?

 

DS notification.PNG

 
 
 
 
 
ds workflow notification.PNG
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {



    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item.sys_id); //changed
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.space("\n");
            template.print("\n" + vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue() + "\n");
        }
    }
})(current, template, email, email_action, event);
1 ACCEPTED SOLUTION

@sjjantz : This will work, please use the below script and make sure the notification is configured on [sc_req_item] table.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {



    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.sys_id); //changed
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.space("\n");
            template.print("\n" + vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue() + "\n");
        }
    }
})(current, template, email, email_action, event);

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

View solution in original post

7 REPLIES 7

@sjjantz : If that's the case, please change the table on your notification to'sc_req_item' and select it in the notification drop-down in your flow. If it doesn't show up, please refresh the screen and try.

 

Also your email script needs to be updated from [current.request_item.sys_id] to [current.sys_id] as we are changing the table from sc_req_item to sc_task.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Unfortunately, this is where I started. While the workflow then sends an email, it won't provide the RITM variables in the body of the email. So perhaps what I need is somebody to help me modify the mail script to be able to pull the variables. 

@sjjantz : This will work, please use the below script and make sure the notification is configured on [sc_req_item] table.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {



    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.sys_id); //changed
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.space("\n");
            template.print("\n" + vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue() + "\n");
        }
    }
})(current, template, email, email_action, event);

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.