Need to send folder credentials like username and password through mid server script include.

Tejashri2
Tera Contributor

Hello Guys, 

I have a requirement like needing to send a csv file with sctask information to a shared drive on window network server.Currently I am able to send the file on the Windows network server. But for security reasons I have to pass the "Username" and "Password" through the mid server script include to access the folder on the Shared Drive then write the file to the folder.   I don't know how to access the folder with credentials. 

 

Thanks in Advance!

2 REPLIES 2

msd93
Kilo Sage

Try below sample script include:

var SharedDriveAccess = Class.create();
SharedDriveAccess.prototype = {
initialize: function() {
},

// Function to write a file to the shared drive folder
writeFileToSharedDrive: function(username, password, catalogTaskNumber, fileContent) {
try {
// Define your shared drive folder path
var sharedDriveFolder = "/path/to/shared/drive/folder/";

// Create a unique file name using the catalog task number
var fileName = "task_" + catalogTaskNumber + ".csv";

// Construct the full file path
var filePath = sharedDriveFolder + fileName;

// Create an instance of GlideExternalDataSource to access the shared drive
var dataSource = new GlideExternalDataSource();

// Set the authentication credentials
dataSource.setAuthentication(username, password);

// Write the file to the shared drive
dataSource.writeFile(filePath, fileContent);

gs.info("File '" + fileName + "' written to the shared drive folder.");
} catch (e) {
gs.error("Error writing the file to the shared drive: " + e.getMessage());
}
},

type: 'SharedDriveAccess'
};

 

Please let me know if it helped you.

Tejashri2
Tera Contributor

Thanks for your reply.

But currently i am facing the issue from "// Create an instance of GlideExternalDataSource to access the shared drive" line.