大佬教程收集整理的这篇文章主要介绍了ServiceNow - 更改 Midserver 中的文件名,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在尝试在计划导出后替换中间服务器中的文件名。
这里的想法是文件的名称采用“file_name_datetiR_303_11845@e”格式,客户需要“datetiR_303_11845@e_file_name”才能让另一个系统正确读取该文件。
我的主要想法是在导出后将文件重命名为正确的格式,但如果有办法将文件名更改为所需的文件名,我也可以这样做。
我很想听听你们的意见,因为我不知道我该怎么做。
提前致谢。
如果有人对答案感兴趣,请参见下文:
脚本包括:
initialize: function() {
this.filePath = gs.getProperty('directory_path');
this.midServer = gs.getProperty('midserver');
this.authMidServerBase64 = gs.getProperty('authmidserver');
},nameChange: function(exportSetName) {
var exportGr = new GlideRecord("sys_export_set_run");
exportGr.addEncodedQuery("set.nameSTARTSWITH" + exportSetName);
exportGr.orderByDesc("completed");
exportGr.query();
if (exportGr.next()) {
var attachSysID = exportGr.ecc_agent_attachment.sys_id;
}
var attachGr = new GlideRecord("sys_attachment");
attachGr.addEncodedQuery("table_sys_idSTARTSWITH" + attachSysID);
attachGr.query();
if (attachGr.next()) {
var attachName = attachGr.file_name;
var attachDate = attachName.match((/\d+/));
var newName = attachDate + '_' + exportSetName + '.csv';
}
var jspr = new JavascriptProbe(this.midServer);
jsPR.setName('FilenameChange'); // This can be any name
jsPR.setJavascript('var ddr = new MidServer_script_include(); res = ddr.execute();');
jsPR.addParameter("verbose","true");
jsPR.addParameter("skip_sensor","true"); // prevent Discovery sensors running for the ECC input
jsPR.addParameter("filename",this.filePath + "\\" + attachName);
jsPR.addParameter("filePath",this.filePath);
jsPR.addParameter("newName",this.filePath + "\\" + newName);
jsPR.addParameter("operation","rename");
return jsPR.create();
},
中间服务器脚本包括:
initialize: function() {
/**
*** Set up the Packages references
**/
this.File = Packages.java.io.File;
this.FiLeoutputStream = Packages.java.io.FiLeoutputStream;
this.FileInputStream = Packages.java.io.FileInputStream;
this.Path = Packages.java.nio.file.Path;
this.Paths = Packages.java.nio.file.Paths;
this.Files = Packages.java.nio.file.Files;
this.StandardCopyOption = Packages.java.nio.file.StandardCopyOption;
/**
/* Set up the parameters
**/
this.verbose = probe.getParameter("verbose");
this.filePath = probe.getParameter("filePath");
this.filename = probe.getParameter("filename");
this.operation = probe.getParameter("operation");
this.newName = probe.getParameter("newName");
result = "initialize complete";
},execute: function() {
if (this.operation == 'rename') {
this.fileRename(this.filename,this.newName);
}
return result;
},fileRename: function(filename,newName) {
result+= "\r\n Renaming file.";
this._debug(result);
try {
var res = this._moveFile(filename,newName);
} catch (E) {
result += "\r\n Erro no renomeamento do ficheiro: " + e;
this._debug(result);
}
},_moveFile: function(initialPath,targetPath) {
try {
this._debug("InitiaTing file move function");
var inPath = this.Paths.get(initialPath);
var tgPath = this.Paths.get(targetPath);
var res = this.Files.move(inPath,tgPath,this.StandardCopyOption.replaCE_EXISTinG);
result += "File successfully moved from: " + initialPath + " to: " + targetPath + " \r\n Result: " + res;
this._debug(result);
} catch (E) {
this._debug('Error:' + E);
}
},_debug: function(m) {
if (this.verbose == "true") {
ms.log("::: Mid Server script include logger ::: " + m);
}
},
https://community.servicenow.com/community?id=community_question&sys_id=a56b38a6db326490fa192183ca961987
以上是大佬教程为你收集整理的ServiceNow - 更改 Midserver 中的文件名全部内容,希望文章能够帮你解决ServiceNow - 更改 Midserver 中的文件名所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。