3

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

2 回答 2

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"));
  }
于 2017-06-14T06:17:03.340 回答
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"));
}
于 2017-07-21T12:38:51.980 回答