How do I export block group table to csv using perspective

I am new to scripting. I have tags in a block transaction group. I like the way the table looks with my tags. How do I configure my export to .csv button on page view to use the date range and pull the data from table to export to csv. I know my file location works because we have another page that is setup similar, only they had the script make the .csv columns and rows. I just need to pull the data from table I created. I would also like to show some of the table data on a page if possible. I’ve tried multiple things and its not working.

How do transaction groups play into this? When you say table do you mean the transaction group configuration?

Transaction group implies that the data is being stored in a database, so presumably you would need to somehow query the database for the data and then through one of a few methods convert that data to a .csv.

However, note that perspective doesn’t have direct access to the users file system so you will also need to prompt the user to download the file, if that is the intention you are after.

It is not as simple as just converting tags subscribed to a transaction group to a .csv file, and the true intent of your application will change the method that could/should be used.

Please show some of what you attempted and what you got. Please post code as text, then use the “preformatted text” button </> to make it look good. Please use your computer’s screen capture tool instead a camera for screenshots. (Almost impossible to avoid those moiré patterns with a camera.)

Here is a few pictures showing where i’m at. Right now I would atleast like to call and export the whole Wrap_Temps2 query and then work on the start and end dates after I get that working. Any help would be great. I apologize I’m new to scripting. I can only post 3 pics at the moment. I have another that shows an existing view in program that is similar, only they used script to build the .csv with historical tags.

Were you able to check out my screenshots

  1. The script you have provided is incomplete. You are missing the ) on line 7.
  2. Your script will not run, because your named query is configured with 2 parameters (even though you aren’t using them.) On top of that, the parameters argument is not optional and must be included even if you only supply an empty dictionary.
  3. When called from a gateway scope, the project name must also be supplied to the function.

Something like this:

data = system.db.runNamedQuery('EggLife','Line 2/WrapTemp',{'myValueX':None,'myValueY':None})
csv = system.dataset.toCSV(data)

Also, please use the pre-formatted text option </> to post script. That way those who are trying to help can easily read and work with it.

Still does not work, maybe its the file location now.

As I said earlier. Perspective does not have direct access to the users file system.

If your desire is to download this file to a client’s workstation you will have to use the function.

In you first post you mention a transaction group and a table, however, you haven’t show either. How does that tie into whatever it is you’re trying to accomplish?

Got it. Thank you!!! Now I need to add my timestamp row. I should be able to get it from here. Thank you thank you

When I export to .CSV the timestamp does not look right, but when you open with notepad it is there. Any ideas for getting the .CSV to show correct timestamp?

You need to set the format for the column in excel. That is an excel problem. Ignition is only creating a CSV file, which does not contain any encoding for formatting.

1 Like