Skip to main content
Apr 20, 2017 10:02 AM UTC
Question

How to create a new folder and open the same using javascript from triggers?

My intention is to create a new folder when a field is checked in an Item type using triggers.

I found difficulty in writing javascript to do the same as it does not support ActiveX to access the file base.

Node js can be used but it does not seem to work with PTC

11 replies

17-Peridot
Apr 21, 2017 11:52 AM UTC

Hello,

can you please let us know your business case. Otherwise it would be difficult for us to answer.

Are you asking about our Integrity Trigger capabilities?

Volker

Translate
Apr 24, 2017 3:28 AM UTC

Hello Volker,

The actual requirement is that, we have a common shared folder where we store large documents which cannot be a part of attachment for a item type.

For example, I create an item type "Bug" with the Item ID 81234, there is an option called "Attach large files". If that option is checked, I want a trigger to automatically create a folder by the name "ID_81234" and open the same as soon as the user creates the item type "Bug".

To achieve this, I am in need to create and open folders using JavaScript for triggers.

Translate
17-Peridot
Apr 24, 2017 7:20 AM UTC

Hello Sujith,

this explains a bit more.

What you exactly mean by "open the same".

Open in what?

What I have understood is that you are going to crerate an issue and you plan to automate to create a corresponding project (or folder) in Integrity Source.

Usually, you create a sandbox to upload some data into Integrity Source.

Do you consider to use a local sandbox?

Translate
2-Explorer
Apr 25, 2017 2:25 PM UTC

You can use Java objects within the JavaScript trigger to do file IO e.g.

var propsFile = new java.io.File(propsFileName);

// Make missing directories

propsFile.getParentFile().mkdirs();

var tempOS = new java.io.FileOutputStream(propsFileName, true);

tempOS.close();

// Check that there is write access to the file

if( ! propsFile.canWrite() ){

  abortTrigger("ERROR:  Cannot access file: " + propsFileName);

}

Translate
Apr 26, 2017 4:16 AM UTC

Hello Jason,

Thank you for the response. For now my requirement does not include file IO operations. It is just simple folder creation and access.

Can I use mkdirs() or any similar functions to create a folder through trigger?

Thanks

Translate
2-Explorer
Apr 26, 2017 6:08 AM UTC

Yes.You can do something like:

(new java.io.File("C:\\Program Files\\Integrity\\IntegrityServer10.8\\data\\triggers\\scripts\\test")).mkdirs();

Translate