3

In ServiceNow, I have written script in business login - script actions. While adding and deleting I am getting sysId but when renaming the attachment I am not able to get 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();
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Nayas Subramanian
  • 2,269
  • 21
  • 28
  • What is `current` in this context? Also, this is a script action, so I'm guessing triggered by an event. It would help to know what the event is and what triggers it (e.g. eventQueue in an after update business rule). – Joey Jun 12 '17 at 15:35
  • What is the event when renaming the attachement? There is an event with attachment.rename in script action in that i have added the above code. Any other event i can plug with. – Nayas Subramanian Jun 13 '17 at 03:51
  • @Joey What is the event when renaming the attachement? There is an event with attachment.rename in script action in that i have added the above code. Any other event i can plug with – Nayas Subramanian Jun 13 '17 at 04:05
  • I see an event named `attachment.renamed`, is that what you mean? That gets triggered when an attachment file name is changed through the UI. – Joey Jun 14 '17 at 00:01

2 Answers2

2

try this

  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"));
  }
Abinash
  • 471
  • 3
  • 13
0

Just run this code in your 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"));
}
azro
  • 53,056
  • 7
  • 34
  • 70