Can we create flow using script

VaibhavP5059517
Giga Guru

Hey All,
I wanted to know that can we create flow using script in ServiceNow and which table stores which part of flow.

1 ACCEPTED SOLUTION

Diogo Ramos
Tera Sage

Hey, going directly to your question, yes you can create a flow via code, but this has to be done via the now SDK as far as I am aware, you cannot just run a script in SN and create a flow at least in a easy way.

From SDKK 4.3.0 you normally have access to the fluent FLOW API , meaning you can also use AI to generate these flows. sdk-examples/flow-sample/src/fluent/flow-trigger-catalog-item.now.ts at main · ServiceNow/sdk-exampl...

I Hope this helps !

View solution in original post

23 REPLIES 23

Yes, my requirement is creating flow using script, is it possible.

hello @VaibhavP5059517 ,

 

As per my understanding , Answer is No .But there is one API : sn_text2flow

which will get on now assist enabled instance through which you can create flow using script but that is more complex .

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya

Hello @VaibhavP5059517 ,

 

I hope you are doing well . Does your query is resolved ?

 

If my response helps you then mark it as helpful and accept as solution.

Regards,

Aditya

1__PrabakaranC
Tera Expert

Hi @VaibhavP5059517 

Yes, you can create a Flow record and invoke an existing flow through script. However, adding Flow Designer actions (such as Create Record, Approval, Update Record, etc.) by directly inserting records into backend tables is not recommended because the action configuration is stored across multiple internal tables and relationships.

You can also retrieve:

  • Flow Sys ID from the sys_hub_flow table.

  • Execution Sys ID (Context ID) from the sys_flow_context table when the flow is executed using sn_fd.FlowAPI.startFlow().

If this helps, please mark the answer as Helpful.


Thanks,
Prabakaran C
LinkedIn: https://www.linkedin.com/in/prabakaran-c-534b6826a


The short answer is yes, absolutely! You can trigger, start, or execute a Flow, Subflow, or Action using JavaScript in ServiceNow.

ServiceNow provides a built-in API called "sn_fd.FlowAPI" specifically for this purpose. You can use it in server-side scripts like Business Rules, Script Includes, Scheduled Jobs, or UI Actions.

Here is a quick guide on how to do it.

  1. Open your Flow in Flow Designer.

  2. Click the More Actions button (the three dots  ... in the top right corner).

  3. Select Create Code Snippet.

  4. Copy the auto-generated script and paste it directly into your Business Rule or Script Include.

If you find this response helpful, please mark it as Correct and Helpful.

 


Regards,
Priyam Sharma