Script Field Type (How to use it in flow designer).

JPing
Tera Expert

Hello All,

I am doing a POC and trying to understand the script field.

I have a new table, and in the table i have a field called "insert_script" --> it is field type script.

The goal is when a record is inserted it will execute the script. This script could be anything on the server side and is unique to each record.

Question 1: how do call the execution of this script in flow designer, as I will have a flow that will trigger on record insert (into table)?

Note i do understand that in flow designer, i can create an inline script at almost every action, the problem it is always the same script. I would like the unique script of the record to execute in flow designers.

I feel like this would be similar to how a mail scripts' script field get called by a notification.

I find the word "script" is so common in SN that it hard to google a similar issue.

Thank you in advance.
-Jeff

2 REPLIES 2

Hitoshi Ozawa
Giga Sage
Giga Sage

Create an action with Script Step.

In the script step, read in the JavaScript to execute and use "eval(<JavaScript string>)" to execute it.

Tried it with the following code to set user to active and was able to update user's record.

(function execute(inputs, outputs) {
var s = 'var gs = new GlideRecord("sys_user");gs.addQuery("sys_id", "62826bf03710200044e0bfc8bcbf5df2");gs.query();if (gs.next()) {  gs.active = true;gs.update();}';
eval(s);
})(inputs, outputs);

Thanks Hitoshi, 

eval() is a pretty interesting solutions, I managed to test it out and it appears to give me what I'm looking for. I read up on eval() however and it doesn't look like this is ever a recommended for best practices. I wonder how SN executes script fields in their own stuff... like notification scripts, client scripts, record producers script fields. 

 

This was very helpful.