ServiceNow renames the application without getting the SysId

In ServiceNow, I wrote a script in business login - action script. When adding and removing, I get the sysId, but when renaming the attachment, I cannot get the 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();
    }
}

      

+3


source to share


2 answers


try it



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

      

+2


source


Just run this code in background Script



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

      

0


source







All Articles