ServiceNow重命名附件未获得SysId

时间:2017-06-12 11:56:04

标签: servicenow servicenow-rest-api

在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();
    }
}

2 个答案:

答案 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"));
}