- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 02:00 PM
Hi,
I am trying to generate automatic task in custom table through scheduled job. I want to add attachment as well along with task creation. New record is getting created successfully but attachment is not getting added. How can I achieve this?
var gr = new GlideRecord("sys_attachment");
var x = gr.get("24c0f46d1b94eddc7f27db58b04bcb1d");
var ptask = new GlideRecord('u_property_it_tasks');
//ptask.get('d04fe0e51b9ce5187ccda687bd4bcbb7');
ptask.initialize();
ptask.short_description = 'Weekly Check Sun/Mon';
ptask.description = 'Perform maintenance please refer to the attached document.';
ptask.assignment_group = '92821b43db6db6401c7c5dd5ce9619ca';
var attachment = new GlideSysAttachment();
attachment.copy(gr, x, ptask, current.sys_id);
ptask.insert();
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 03:05 PM
I think the code would be something like this.
var ptask = new GlideRecord('u_property_it_tasks');
ptask.initialize();
ptask.short_description = 'Weekly Check Sun/Mon';
ptask.description = 'Perform maintenance please refer to the attached document.';
ptask.assignment_group = '92821b43db6db6401c7c5dd5ce9619ca';
var sysId = ptask.insert();
var attachment = new GlideSysAttachment();
attachment.copy('u_property_it_tasks', <source sys_id>, 'u_property_it_tasks', sysId);
I am still not clear from where you are copying the attachment and that is why I put <source sys_id>.
I assume this new task is related somehow to the source. Maybe it is a child of it. If that would be the case, I would have expected adding ptask.parent = <something> and that something is where you would be copying the attachments from. Then the <source sys_id> would be ptask.parent
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 03:10 PM
Try this. You will be copying the attachments on the "185119651b9029187ccda687bd4bcbfd" record to the newly created one.
var sourceSysId = '185119651b9029187ccda687bd4bcbfd';
var ptask = new GlideRecord('u_property_it_tasks');
ptask.initialize();
ptask.short_description = 'Weekly Check Sun/Mon';
ptask.description = 'Perform maintenance please refer to the attached document.';
ptask.assignment_group = '92821b43db6db6401c7c5dd5ce9619ca';
var targetSysId = ptask.insert();
var attachment = new GlideSysAttachment();
attachment.copy('u_property_it_tasks', sourceSysId , 'u_property_it_tasks', targetSysId);
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 03:05 PM
I think the code would be something like this.
var ptask = new GlideRecord('u_property_it_tasks');
ptask.initialize();
ptask.short_description = 'Weekly Check Sun/Mon';
ptask.description = 'Perform maintenance please refer to the attached document.';
ptask.assignment_group = '92821b43db6db6401c7c5dd5ce9619ca';
var sysId = ptask.insert();
var attachment = new GlideSysAttachment();
attachment.copy('u_property_it_tasks', <source sys_id>, 'u_property_it_tasks', sysId);
I am still not clear from where you are copying the attachment and that is why I put <source sys_id>.
I assume this new task is related somehow to the source. Maybe it is a child of it. If that would be the case, I would have expected adding ptask.parent = <something> and that something is where you would be copying the attachments from. Then the <source sys_id> would be ptask.parent
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 03:09 PM
Its working now, thank you!!