Skip to main content
April 20, 2017
Question

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

  • April 20, 2017
  • 2 replies
  • 8040 views

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

2 replies

17-Peridot
April 21, 2017

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

April 24, 2017

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.

17-Peridot
April 24, 2017

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?

1-Visitor
April 25, 2017

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);

}

April 26, 2017

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

1-Visitor
April 26, 2017

Yes.You can do something like:

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