How to copy attachments based on variables value

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have few variables on the sc task table where i have one variable which is of type attachment. I want to copy that attachment into the another variable's values records. For eg. oat certificate is of type of attachment, whatever attachment is there i want to copy it into the server names variable records which is a list collector so suppose i have selected 3 servers into it so that oat certificate attachment should copy into these 3 server records.

 

Second requirement is, all the attachments which is there for all attachment type variables except the oat certificate. All should copy into the application name variable which is a reference field and the reference table is business application. So, suppose xyz business app i have selected in this application name field, so all the attachments which are there on sc task table for all attachment type variables except the oat certificate attachment variable. It should copy all these attachments into xyz business app record which is selected in the application name field.

 

Here is the code for the same.

 

It is an after BR on sc task table for an specific catalog item.

 

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

    var taskSysID = current.getValue('sys_id');
    var oatSysID = current.variables.database_oat_certificate.sys_id.toString();
    gs.log("Hi" +oatSysID);
    var serversSysID = current.getValue('current.variables.server_name_s.sys_id.toString()');
    gs.log("Hi1" + serversSysID);
    var appSysID = current.getValue('current.variables.application_name.sys_id.toString()');
    gs.log("Hi2" + appSysID);

    var attachment = new GlideSysAttachment();

    gs.log("Hi3" + oatSysID);
    gs.log("Hi4" + serversSysID);
    attachment.copy('sc_task', oatSysID, 'cmdb_ci_server', serversSysID);
    gs.log("Hi5" + oatSysID);
    gs.log("Hi6" + serversSysID);
    gs.log("Hi7" + taskSysID);
    gs.log("Hi8" + appSysID);
    attachment.copy('sc_task', taskSysID, 'cmdb_ci_business_app', appSysID);
    gs.log("Hi9" + taskSysID);
    gs.log("Hi10" + appSysID);

})(current, previous);
 
I am getting null or undefined in the logs for these variables value.
 
Kindly help me in it.
Thanks
4 REPLIES 4

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Poorva Bhawsar ,

 

Can u try this solution suggested by ankur.

 

Thanks,

Danish

 

Where is the suggested solution.

This is not helpful for my scenario.

 

Any other suggestions for this?