Copy Attachment UI Action

matthew_smith
Kilo Explorer

HI,

I am trying to create a UI Action that takes the info from a Facilities Request and copies that into an incident. I have most of it working except the copying of any attachments, what am I doing wrong?

I am a complete novice at this and have completely hashed this together!!

Any help is most appreciated!

Matt

var fac = new GlideRecord("incident");

GlideSysAttachment.copy('facilities_request', current.sys.id, 'incident', current.sys_id);

fac.short_description = "Created from Facitlities Record " + current.number + ": " + current.short_description;

fac.caller_id = current.opened_for;

var sysID = fac.insert();

current.u_reference = sysID;

var mySysID = current.update();

gs.addInfoMessage("Incident " + fac.number + " created for this Facilities Record");

action.setRedirectURL(facilities_request);

action.setReturnURL(current);

1 ACCEPTED SOLUTION

Hi Matt,



Updated the script. Can you copy my script above again and try it now .


Basically there was mistake in current.sys.id and it should be current.sys_id


View solution in original post

7 REPLIES 7

Gurpreet07
Mega Sage

Hi Matt,



Please find the code below



var fac = new GlideRecord("incident");


GlideSysAttachment.copy('facilities_request', current.sys.id, 'incident', fac.sys_id);


fac.short_description = "Created from Facitlities Record " + current.number + ": " + current.short_description;


fac.caller_id = current.opened_for;


var sysID = fac.insert();


current.u_reference = sysID;


var mySysID = current.update();




gs.addInfoMessage("Incident " + fac.number + " created for this Facilities Record");


action.setRedirectURL(facilities_request);


action.setReturnURL(current);


Shahed Shah1
Tera Guru

Just looking at the following line:


GlideSysAttachment.copy('facilities_request', current.sys.id, 'incident', current.sys_id);



Shouldn't the last parameter be fac.sys_id?


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Matt Smith



There were few errors in your code. I've modified it. Please copy the below code as is and let me know the outcome.


var fac = new GlideRecord("incident");


fac.short_description = "Created from Facitlities Record " + current.number + ": " + current.short_description;


fac.caller_id = current.opened_for;


var sysID = fac.insert();


GlideSysAttachment.copy('facilities_request', current.sys_id, 'incident', sysID);


current.u_reference = sysID;


var mySysID = current.update();




gs.addInfoMessage("Incident " + fac.number + " created for this Facilities Record");


action.setRedirectURL(facilities_request);


action.setReturnURL(current);


Thank you all for your help,



, but it still doesn't appear to work? the log shows that it ran OK, but I still cant see the attachment in the incident?



Thank you again for your help



<xml>



<sysevent>



<claimed_by>app80026.lhr1.service-now.com:omegauwdev003</claimed_by>


<descriptive_name/>


<instance>a5f443366f3f75001e9e90354b3ee445</instance>


<name>attachment.uploaded</name>


<parm1>facilities_request</parm1>


<parm2>3ad483366f3f75001e9e90354b3ee4ec</parm2>


<process_on>2015-05-07 10:37:22</process_on>


<processed>2015-05-07 10:37:31</processed>


<processing_duration>30</processing_duration>


<queue/>


<state>processed</state>


<sys_created_by>Matthew.Smith</sys_created_by>


<sys_created_on>2015-05-07 10:37:22</sys_created_on>


<sys_id>e9f443366f3f75001e9e90354b3ee44b</sys_id>


<sys_mod_count>1</sys_mod_count>


<sys_updated_by>system</sys_updated_by>


<sys_updated_on>2015-05-07 10:37:31</sys_updated_on>


<table>sys_attachment</table>


<uri/>


<user_id>e158e2390f612100009a79f692050e5e</user_id>


<user_name/>


</sysevent>


</xml>