GlideSysAttachment().copy Not copying the attachment - HR Scoped application

Mrman
Tera Guru

Hi Team,

I have created a after insert BR to insert a HR task and then copy a specific attachment from a Case to HR task .

The attachment is not getting copied to HR task. Please suggest 

All the log messages are getting triggered correctly , but the attachment is not found on target record.

(function executeRule(current, previous /*null when async*/ ) {

    gs.info("the BR triggerred for status");

    var grCattch = new GlideRecord('sys_attachment');
    grCattch.addQuery('table_name', 'sn_hr_core_case_workforce_admin');
    grCattch.addQuery('table_sys_id', current.sys_id);
	grCattch.addEncodedQuery('file_nameSTARTSWITHStatus Record Certificate');
    grCattch.query();

    if (grCattch.next()) {
		

        var grCmnl = new GlideRecord('sn_hr_core_task');
        grCmnl.initialize();
        grCmnl.parent = current.sys_id;
        grCmnl.assignment_group = '3506330cdbc92054e803f3551d9619b0';
        grCmnl.state = '10';
        grCmnl.short_description = "Validate Status Record";
        grCmnl.insert();
		

gs.info("the record status is found " + 'attchsysid----' + grCattch.getUniqueValue() + 'attchtable---' + grCattch.getTableName() + 'tasktable----' + grCmnl.getTableName() + 'tasksysid---' + grCmnl.getUniqueValue());

		new GlideSysAttachment().copy(grCattch.getTableName(), grCattch.getUniqueValue(), grCmnl.getTableName(), grCmnl.getUniqueValue());
    }

 

22 REPLIES 22

sachin_namjoshi
Kilo Patron
Kilo Patron

Update your code like below

 

(function executeRule(current, previous /*null when async*/ ) {

    gs.info("the BR triggerred for status");

    var grCattch = new GlideRecord('sys_attachment');
    grCattch.addQuery('table_name', 'sn_hr_core_case_workforce_admin');
    grCattch.addQuery('table_sys_id', current.sys_id);
	grCattch.addEncodedQuery('file_nameSTARTSWITHStatus Record Certificate');
    grCattch.query();

    if (grCattch.next()) {
		

        var grCmnl = new GlideRecord('sn_hr_core_task');
        grCmnl.initialize();
        grCmnl.parent = current.sys_id;
        grCmnl.assignment_group = '3506330cdbc92054e803f3551d9619b0';
        grCmnl.state = '10';
        grCmnl.short_description = "Validate Status Record";
        var sid = grCmnl.insert();
		

gs.info("the record status is found " + 'attchsysid----' + grCattch.getUniqueValue() + 'attchtable---' + grCattch.getTableName() + 'tasktable----' + grCmnl.getTableName() + 'tasksysid---' + grCmnl.getUniqueValue());

		new GlideSysAttachment().copy(grCattch.table_name, grCattch.sys_id, 'sn_hr_core_task', sid);
    }

 

Regards,

Sachin

@sachin.namjoshi I have updated the code as you mentioned but still the attachment is not getting copied to the target record , could not see that attachment.

Please suggest . Updated the code as below .

(function executeRule(current, previous /*null when async*/ ) {

    var grCattch = new GlideRecord('sys_attachment');
    grCattch.addQuery('table_name', 'sn_hr_core_case_workforce_admin');
    grCattch.addQuery('table_sys_id', current.sys_id);
	grCattch.addEncodedQuery('file_nameSTARTSWITHStatus Record Certificate');
    grCattch.query();

    if (grCattch.next()) {
		
        var grCmnl = new GlideRecord('sn_hr_core_task');
        grCmnl.initialize();
        grCmnl.parent = current.sys_id;
        grCmnl.assignment_group = '3506330cdbc92054e803f3551d9619b0';
        grCmnl.state = '10';
        grCmnl.short_description = "Validate Status Record";
        var sid = grCmnl.insert();
		
gs.info("the record criminal is found " + 'attchsysid----' + grCattch.getUniqueValue() + 'attchtable---' + grCattch.getTableName() + 'tasktable----' + grCmnl.getTableName() + 'tasksysid---' + grCmnl.getUniqueValue());
//         gs.info("the tasks inserted is : " + grCmnl.sys_id);
		new GlideSysAttachment().copy(grCattch.table_name, grCattch.sys_id, 'sn_hr_core_task', sid);
    }







})(current, previous);

Try to print value of sid variable to make sure that record is inserted in sn_hr_core_task table.

Also, run this code in background script to check for any errors to troubleshoot further.

 

Regards,

Sachin

@sachin.namjoshi Yes  the HR task record is getting inserted I am able to open the record and when I open , there is no attachment.

when I run in background script there are no errors and attachment is not getting copied . Please suggest