Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

(SM) Support Tip: JavaScript to write a txt file / add an Attachment to a ticket

JavaScript can manipulate text files on the server, this gives the capability to import data and manipulate it with custom code, for example:


  1. JavaScript to WriteFile:

         //This writes into the RUN directory of the server path 

        var filePath = ".\\mytest.txt";


        The “t” indicates this is a text file

        var FileType = "t";


       // Line Feed

       var sLF = String.fromCharCode(10);


       fileObject = vars.$lo_ucapex;


       // Add a line feed between capability words

       fileObject = fileObject.join(sLF);




       // Add the file as an attachment to Incident IM10001

       addAttachment( “IM10001”, filePath );



2.  JavaScrip to addAttachment



function addAttachment(incidentID,fileName){


var f = new SCFile('incidents');

var rc = f.doSelect("incident.id=\""+ incidentID + "\"");



       if( rc == RC_SUCCESS ){

       var attachObj = new Attachment();

       attachObj.type = "text";

       attachObj.name = fileName;


       var source = readFile(fileName, "t" );

       attachObj.value = source; 


       var attachmentID = f.insertAttachment( attachObj );




Labels (1)
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.