question

Abhishek K avatar image
0 Likes"
Abhishek K asked Jason Lightfoot commented

How to export data to a SQL Database on Model Stop

Hello,

I have built a model in which I want to pull input data from a SQL database using a Database Connector, and then export the output to a table in that same SQL database. I am using Flexsim 18.1.

The question I have is - How to automatically export the data on model stop ?

I will be using windows task scheduler to run the model everyday at a specific time and on model open and reset, I'll refresh the input data. Then, the model will run for a specified time and "on model stop" , I want to write the result to the SQL database.

There is a provision to import data on model reset from the SQL database, but I dont know how to export the data based on the on model stop trigger.

data-export.png

FlexSim 18.1.2
sqlexport data
data-export.png (23.0 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

David Seo avatar image David Seo commented ·
@Abhishek K

Have you ever used 'On Run Stop' trigger in the "ToolBox>Modeling Logic>Model Trigger>On Run Stop" option menu?

0 Likes 0 ·
Abhishek K avatar image Abhishek K David Seo commented ·

Thank you for the response, I have used it, but I dont know the scipt that is needed there to export data into a SQL database

0 Likes 0 ·
Abhishek K avatar image Abhishek K David Seo commented ·

I tried to toggle the export node as flexscript and then used nodefuntion() to execute it but that is not working either

0 Likes 0 ·
toggle-node.png (34.7 KiB)

1 Answer

·
Benjamin W2 avatar image
0 Likes"
Benjamin W2 answered Jason Lightfoot commented

Hi @Abhishek K,

The following code should help. make sure to correctly configure your Data Base Connector.

Also note, the "On Model Stop" trigger may not be the best place to use this code, since it will fire every time you hit the stop button. Consider designing a user event in the Toolbox or using Process Flow to export your data at a certain time.

function_s(model().find("Tools/DatabaseConnectors/DBConnector1"), "exportAll");

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Benjamin W2 avatar image Benjamin W2 commented ·

Hey @Abhishek K, was my answer helpful for you? If so, could you accept it? Otherwise, how else can I help?

0 Likes 0 ·
Rafael O9 avatar image Rafael O9 commented ·

What if I only want to export the last row? and not all the rows...?

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Rafael O9 commented ·
You should ask a new question but it sounds like you need need to add a single row to a table - you could use SQL's "INSERT INTO" for that.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.