Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to copy attachment from one table to another table

Nag9
Tera Expert

Hi 

I have catalog item that should create a CR usimg workflow..

If i raise a ritm along with attachement, the attachement should be appear while the time creating new CR using workflow.

1 ACCEPTED SOLUTION

Ok, here is the updated script.

if(current.variables.cloud_type == 'GCP Project'){
var service = new GlideRecord('change_request');
    service.initialize();
    service.setValue('cmdb_ci','2513c8b2db88f204f6ef7016bf961965');
    gs.log("assigned_to is "+current.variables.assigned_to()+"--"+current.assigned_to);
    service.setValue('assigned_to',current.assigned_to);
    service.setValue('u_automation','CRISP');
    service.setValue('u_work_characterization',"Normal Change");
    service.setValue('category','Application');
    service.setValue('u_chg_env','Production');
	service.setValue('u_test_except', 'no_llc');
	service.setValue('u_classification','Standalone');

service.setValue('u_itil_watch_list','Eldridge_L_Fussell@homedepot.com,ITO_Configuration_Management@homedepot.com,BRIAN_HIGGINBOTHAM@homedepot.com,Nalini_Subu@homedepot.com,JEFFREY_L_MITCHELL@homedepot.com,Brett_Warner@homedepot.com,Barbara_Sanders@homedepot.com,it_security_qualys@homedepot.com,ALVA_JENKINS-HOUSTON1@homedepot.com,JAY_ROGERS@homedepot.com');
	
    service.setValue('u_deployment_environment','Google Cloud Platform');
	service.setValue('description',current.variables.u_gcp_project_name +','+current.variables.life_cycle+','+current.variables.workload_description);
    service.setValue('u_size','Normal');
    service.setValue('u_downtime_required_','No');
    service.setValue('u_test_perf','No');
    service.setValue('short_description','Google Cloud Platform - New Project');
    gs.log("values are "+current.opened_by.getDisplayValue()+"--"+current.variables.opened_by);
    service.setValue('u_validated_by', current.opened_by.getDisplayValue());
	
	service.setValue('u_subexperience', current.variables.sox);
	service.setValue('u_subexperience', current.variables.pci);
	service.setValue('u_subexperience', current.variables.financial_impacting);
	service.setValue('u_subexperience', current.variables.restricted_data);
	service.setValue('u_subexperience', current.variables.pii_confidential);
	service.setValue('ustart_date', current.variables.requested_governance_review_date);
	service.setValue('u_project_id', current.variables.project_id);
	service.setValue('u_subexperience', current.variables.subexperience);
	service.setValue('justification', current.variables.business_justification);
	
	
	
    var cr_sys_id = service.insert();

	//service.setValue('u_project_id',current.variables.project_name);
    //copy the attachments of RITM to the above created CR.
    GlideSysAttachment.copy('sc_req_item',current.sys_id,'change_request',cr_sys_id);	


}

View solution in original post

17 REPLIES 17

ok,so your BR is running. try this code and share me the logs output, if it does not work.

(function executeRule(current, previous /*null when async*/) {
	// Add your code here
	if (current.table_name =='sc_req_item')
        {
          //check if the attachment is uploaded for our cat item or not.
          gs.log('inside the loop');
	  var req= new GlideRecord('sc_req_item');
          req.addQuery("sys_id",current.table_sys_id);
          req.addQuery("cat_item","3b58935fdbf923801ac0105f68961901");
	  req.query();
	  if (req.next())
	    {
		var atch= new GlideRecord('change_request');
		atch.addEncodedQuery('number=CHG0451037');
		atch.query();
		if (atch.next())
		{
			GlideSysAttachment.copy('sc_req_item',req.sys_id,'change_request',atch.sys_id);	
		}
	    }
	}
})(current, previous);

Here is the run script im usimg in workflow if(current.variables.cloud_type == 'GCP Project'){ var service = new GlideRecord('change_request'); service.initialize(); service.setValue('cmdb_ci','2513c8b2db88f204f6ef7016bf961965'); gs.log("assigned_to is "+current.variables.assigned_to()+"--"+current.assigned_to); service.setValue('assigned_to',current.assigned_to); service.setValue('u_automation','CRISP'); service.setValue('u_work_characterization',"Normal Change"); service.setValue('category','Application'); service.setValue('u_chg_env','Production'); service.setValue('u_test_except', 'no_llc'); service.setValue('u_classification','Standalone'); service.setValue('u_itil_watch_list','Eldridge_L_Fussell@homedepot.com,ITO_Configuration_Management@homedepot.com,BRIAN_HIGGINBOTHAM@homedepot.com,Nalini_Subu@homedepot.com,JEFFREY_L_MITCHELL@homedepot.com,Brett_Warner@homedepot.com,Barbara_Sanders@homedepot.com,it_security_qualys@homedepot.com,ALVA_JENKINS-HOUSTON1@homedepot.com,JAY_ROGERS@homedepot.com'); service.setValue('u_deployment_environment','Google Cloud Platform'); service.setValue('description',current.variables.u_gcp_project_name +','+current.variables.life_cycle+','+current.variables.workload_description); service.setValue('u_size','Normal'); service.setValue('u_downtime_required_','No'); service.setValue('u_test_perf','No'); service.setValue('short_description','Google Cloud Platform - New Project'); gs.log("values are "+current.opened_by.getDisplayValue()+"--"+current.variables.opened_by); service.setValue('u_validated_by', current.opened_by.getDisplayValue()); service.setValue('u_subexperience', current.variables.sox); service.setValue('u_subexperience', current.variables.pci); service.setValue('u_subexperience', current.variables.financial_impacting); service.setValue('u_subexperience', current.variables.restricted_data); service.setValue('u_subexperience', current.variables.pii_confidential); service.setValue('ustart_date', current.variables.requested_governance_review_date); service.setValue('u_project_id', current.variables.project_id); service.setValue('u_subexperience', current.variables.subexperience); service.setValue('justification', current.variables.business_justification); service.insert(); //service.setValue('u_project_id',current.variables.project_name); }

Ok, here is the updated script.

if(current.variables.cloud_type == 'GCP Project'){
var service = new GlideRecord('change_request');
    service.initialize();
    service.setValue('cmdb_ci','2513c8b2db88f204f6ef7016bf961965');
    gs.log("assigned_to is "+current.variables.assigned_to()+"--"+current.assigned_to);
    service.setValue('assigned_to',current.assigned_to);
    service.setValue('u_automation','CRISP');
    service.setValue('u_work_characterization',"Normal Change");
    service.setValue('category','Application');
    service.setValue('u_chg_env','Production');
	service.setValue('u_test_except', 'no_llc');
	service.setValue('u_classification','Standalone');

service.setValue('u_itil_watch_list','Eldridge_L_Fussell@homedepot.com,ITO_Configuration_Management@homedepot.com,BRIAN_HIGGINBOTHAM@homedepot.com,Nalini_Subu@homedepot.com,JEFFREY_L_MITCHELL@homedepot.com,Brett_Warner@homedepot.com,Barbara_Sanders@homedepot.com,it_security_qualys@homedepot.com,ALVA_JENKINS-HOUSTON1@homedepot.com,JAY_ROGERS@homedepot.com');
	
    service.setValue('u_deployment_environment','Google Cloud Platform');
	service.setValue('description',current.variables.u_gcp_project_name +','+current.variables.life_cycle+','+current.variables.workload_description);
    service.setValue('u_size','Normal');
    service.setValue('u_downtime_required_','No');
    service.setValue('u_test_perf','No');
    service.setValue('short_description','Google Cloud Platform - New Project');
    gs.log("values are "+current.opened_by.getDisplayValue()+"--"+current.variables.opened_by);
    service.setValue('u_validated_by', current.opened_by.getDisplayValue());
	
	service.setValue('u_subexperience', current.variables.sox);
	service.setValue('u_subexperience', current.variables.pci);
	service.setValue('u_subexperience', current.variables.financial_impacting);
	service.setValue('u_subexperience', current.variables.restricted_data);
	service.setValue('u_subexperience', current.variables.pii_confidential);
	service.setValue('ustart_date', current.variables.requested_governance_review_date);
	service.setValue('u_project_id', current.variables.project_id);
	service.setValue('u_subexperience', current.variables.subexperience);
	service.setValue('justification', current.variables.business_justification);
	
	
	
    var cr_sys_id = service.insert();

	//service.setValue('u_project_id',current.variables.project_name);
    //copy the attachments of RITM to the above created CR.
    GlideSysAttachment.copy('sc_req_item',current.sys_id,'change_request',cr_sys_id);	


}