Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Error during migrating Attachments

pardhiv
Tera Contributor

I am trying to migrate attachments from one instance to another and using the modified script got from community.

 

I'm getting the following Errors .

 

Access denied to crypto module
Crypto module access is denied for an attachment: no thrown error
Crypto module access is denied for an attachment: com.glide.kmf.CryptoModuleAccessDeniedException: Crypto module access is denied for an attachment: com.glide.kmf.CryptoModuleCipher.getCipher(CryptoModuleCipher.java:111)

 Can I deactivate crypto module temporarily during the migration. 

 

var targetInstanceURL =   "https://XXXXXX.service-now.com/";

var targetUserID = "test_load_2";

var targetUserPassword = "test_load_2";


var answer = "";

var attachmentMsg = "";

var attachmentCount = sendAttachments("u_new_request", "17db86acdbb6cd1073563533f39619bb", "17db86acdbb6cd1073563533f39619bb");

gs.info('KPK1----attachmentCount-----'+attachmentCount);

if (attachmentCount != "none") {

               attachmentMsg =   " Attachments successfully sent: " + attachmentCount[0].toString() + ". Attachments failed to be sent: " + attachmentCount[1].toString();

       } else {

               attachmentMsg =   " Record had no attachments to send.";

       }

gs.info('KPK1----attachmentMsg-----'+attachmentMsg);

function sendAttachments(sourceTable, sourceID, targetID) {

       var answer = [0, 0]; //successful attachments, failed attachments

       

       // Query for any attachments on the current record.

       var attachmentRec = new GlideRecord("sys_attachment");

       attachmentRec.addQuery("table_sys_id", sourceID);

       attachmentRec.addQuery("table_name", sourceTable);

       attachmentRec.query();

       if (attachmentRec.hasNext()) {
		   gs.info('KPK1----ATTACHMENT___FOUND');

               while (attachmentRec.next()) {

                       var attachmentMessage = new sn_ws.RESTMessageV2();

                       attachmentMessage.setHttpMethod("post");

                       attachmentMessage.setBasicAuth(targetUserID, targetUserPassword);

                       attachmentMessage.setEndpoint(targetInstanceURL + "api/now/attachment/file");

                       attachmentMessage.setQueryParameter("table_name", attachmentRec.table_name);

                       attachmentMessage.setQueryParameter("table_sys_id", targetID);

                       attachmentMessage.setQueryParameter("file_name", attachmentRec.file_name);

                       attachmentMessage.setRequestHeader("Content-Type", attachmentRec.content_type);

                       attachmentMessage.setRequestHeader("Accept", "application/json");

                       attachmentMessage.setRequestBodyFromAttachment(attachmentRec.sys_id);


                       var response = attachmentMessage.execute();

                       var responseBody = response.getBody();

                       var httpStatus = response.getStatusCode();

gs.info('KPK1----httpStatus-----'+httpStatus);
				   
                       if (httpStatus.toString() == "201") {

                               answer[0] += 1;

                       } else {

                               answer[1] += 1;

                       }

               }

       } else {

               answer = "none";

       }

	gs.info('KPK1----answer-----'+answer);
	
       return answer;

}

 

3 REPLIES 3

reshmapatil
Tera Guru

Hi @pardhiv ,

 

I think all the records on which attachments are present should be present in your destination instance.

 

If you can activate plugins try to use IDR:

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/instance-data-replicat...

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

rajeshjain24150
Tera Contributor

Did we get any solution for this problem.. I am also facing same issue while transfer encrypted document from one system to another.

Henri
Tera Contributor

I'm facing the same issue as well. This might help some of you but I did not understand what should be filled in to MAP record:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1704422