Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
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
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
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.
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?
Hello Volker,
I do not want to create a source project and this is not at all related to Integrity Source. All I need a physical folder to be created in a computer which is shared by all. It should just be a normal local folder in a Windows operated system.
Hello Sujith,
understand. To my knowledge you cant include any custom code right into triggers to execute local commands.
Triggers are on server, not local.
The only chance I see is to create a custom button (bat file, or java) - behind it you can perform any local operation.
Hello Volker,
That is right. Now is there a possibility that I can run a batch file upon success of a trigger?
Thanks
Hello Sujith,
a trigger runs on server, not on client. No, you cant run any local post action in Integrity Standard.
Assuming your shared drive is on another server, you may develop a listener which catches the item creation events ...
Not sure if this is an option for you.
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);
}
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
Yes.You can do something like:
(new java.io.File("C:\\Program Files\\Integrity\\IntegrityServer10.8\\data\\triggers\\scripts\\test")).mkdirs();
To manage folders and files from a server-side trigger, just use look up and use the "ScriptFileUtilsBean".
From the Event Trigger Java Documentation: This bean provides several convenience methods for file system operations. The bean is available in all triggers from the ScriptEnvironmentBean
via the ScriptEnvironmentBean.getFileUtilsBean()
method.