Flow Action Input Type for Generic Sys_id

William Busby
Tera Guru

I'm developing a 'Cancel Workflow' flow designer action. I need to be able to pass the 'current' gliderecord into the action inputs. I can't predict which table the 'current' gliderecord belongs to so I need to pass a reference to the record. In the past I've used 'Reference.xxxxxx' input types but that requires specifying the table which in this case needs to be open to any type of table (not necessarily an extension of 'task'). 

 

I tried to use type Sys_Id (GUID) but it doesn't seem to represent a true GlideRecord. Any suggestions on what input type to use?

4 REPLIES 4

Manmohan K
Tera Sage

Hi @William Busby ,

 

Try to use a document ID field to reference any record on any table. You need to pair it with a Table Name field.
Basically pass the table name i.e. incident to Table Name field and sys_id to Document id field. 

You can find more details on it  below  - 

https://www.servicenow.com/community/developer-forum/what-is-document-id-field-type-how-to-set-a-val...

Riya Verma
Kilo Sage
Kilo Sage

Hi @William Busby ,

 

Hope you are doing great.

 

 

1. Create an input variable of type 'Reference' in your flow designer action's inputs. Let's name it 'currentRecord' for demonstration purposes

2. Modify the action script to handle the 'current' GlideRecord:

  • Within the flow designer action's script, retrieve the value of the 'currentRecord' input variable.
  • Since the table for the 'current' GlideRecord can vary, you'll need to use generic GlideRecord methods to perform operations on the record.
(function execute(inputs) {
  var currentRecord = inputs.currentRecord;
  
  // Use generic GlideRecord methods to work with the 'current' record
  var gr = new GlideRecord(currentRecord.sys_class_name);
  gr.get(currentRecord.sys_id);
  
  // Perform operations on the 'current' record
  gr.setValue('state', 3); // Example: Set 'state' field to '3'
  gr.update();

})(inputs);

This can help you idynamically handling from any table without specifying the table name in advance.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

William Busby
Tera Guru

I thought I'd post my eventual solution here, inspired partly by both replies. I created two input variables 'id' [Sys ID (GUID)] and 'table' [string]. I also created an output variable 'success' [True/False]. My script is below:

(function execute(inputs, outputs) {

try {
// find record workflow(s) are attached to...
var gr = new GlideRecord(inputs.table);
if (gr.get(inputs.id)) {
new global.Workflow().cancel(gr);
outputs.message = "Workflows sucessfully canceled";
outputs.success = true;
}
else {
var msg = 'Flow action Cancel Workflow unable to find record ' + inputs.id+ ' in table ' + inputs.table;
gs.warn(msg);
outputs.message = msg;
outputs.success = false;
}
}
catch (ex) {
var msg = 'Exception thrown from flow action Cancel Workflow - ' + ex.message;
gs.error(msg);
outputs.message = msg;
outputs.success = false;
}

})(inputs, outputs);

 

Andrei Brutski
Tera Contributor

Hi William,

you have to configure your Input like this:

AndreiBrutski_0-1736255632129.png


then you can take any record as a data pill and the table will be automatically filled in as soon as you drag the data pill in there