The CreatorCon Call for Content is officially open! Get started here.

Need my custom action code to be reviewed because my output is not working properly

yjeon92
Tera Contributor

In Flow Designer - Custom Action, my input is incident_number which refers to Records.

 

This is my Script Step:

 

function execute(inputs, outputs) {
var gr = new GlideRecord(inputs.incident);
gr.query();
if (gr.next()) {
var comments = gr.comments.getJournalEntry(1);
var regex = /\b\d{5}\b/;
var match = comments.match(regex);}

if (match) {
outputs.employee_id = match[0];
}
}

(inputs, outputs);

 

and my output is the employee_id.

 

My goal is to look up the incident record to parse through the additional comment to find the Employee ID and output the employee_id as an integer.  My issue is my output is not working even though the script goes through the testing.  Please help

 

1 ACCEPTED SOLUTION

Hello @yjeon92 

Please Copy Paste and try following code .

 

(function execute(inputs, outputs) {
  var match ;
var gr = new GlideRecord('incident');
gr.addEncodedQuery('number='+inputs.incident_number+'^ORsys_id='+inputs.incident_number);  // add your filed name which your passing as parameter to query in incident table. 
gr.query();
if (gr.next()) {
var comments = gr.comments.getJournalEntry(1);
var regex = /\b\d{5}\b/;
match = comments.match(regex);
}

if (match) {
outputs.employee_id = parseInt(match[0])+1;
}

// ... code ...
})(inputs, outputs);

 

 

View solution in original post

15 REPLIES 15

Mohith Devatte
Tera Sage
Tera Sage

Hello @yjeon92 ,

You match variable is scoped and it should be made public in order to access it outside if statement 

replace you code to below

function execute(inputs, outputs) {
var match ;
var gr = new GlideRecord(inputs.incident);
gr.query();
if (gr.next()) {
var comments = gr.comments.getJournalEntry(1);
var regex = /\b\d{5}\b/;
match = comments.match(regex);
}

if (match) {
outputs.employee_id = match[0];
}
}

(inputs, outputs);

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

@Mohith Devatte 

My output is still not showing the employee id number in the comments:

yjeon92_0-1692980553714.png

The test run was completed but The runtime value doesn't show the output

@yjeon92 can you send a sample comment to me from your journal entry ?

@Mohith Devatte 

So in the incident additional comment, it will show something like this:

 

Received: answering service company

 

name: john doe

phone number: 564-896-9874

email: johndoe@email.com

regarding: missing usb

department: finance

Location: accounting

employee id: 56987

Urgency: no