在ServiceNow中,我在业务登录 - 脚本操作中编写了脚本。 添加和删除时我收到了sysId但是在重命名附件时我无法获得sys_id。
sendnotification();
function sendnotification()
{
try
{
var r = new sn_ws.RESTMessageV2('IqtrackTest', 'AttachmentPost');
r.setStringParameterNoEscape('sys_id',current.sys_id);
r.setStringParameterNoEscape('sysparm_TableName',current.getTableName());
r.setStringParameterNoEscape('Action',"Attachment_Renamed");
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex)
{
var message = ex.getMessage();
}
}
答案 0 :(得分:2)
试试这个
var record = new GlideRecord('sys_attachment');
record.addQuery('user_name',gs.getUserName());
record.orderByDesc('sys_updated_on');
record.setLimit(1);
record.query();
if (record.next())
{
gs.print(record.getValue("sys_id"));
gs.print(record.getDisplayValue("file_name"));
gs.error("file name"+record.getDisplayValue("file_name"));
}
答案 1 :(得分:0)
只需在后台脚本中运行此代码
即可var temp= new GlideRecord('sys_attachment');
temp.addQuery('user_name',gs.getUserName());
temp.orderByDesc('sys_updated_on');
temp.setLimit(1);
temp.query();
if (temp.next()){
gs.print(temp.getValue("sys_id"));
}