Need to send folder credentials like username and password through mid server script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 04:57 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 06:37 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2023 02:01 AM
Thanks for your reply.
But currently i am facing the issue from "// Create an instance of GlideExternalDataSource to access the shared drive" line.