cancel
Showing results for 
Search instead for 
Did you mean: 

How can I move a mail from one folder to another using SAP iRPA?

suvendub98
Explorer
0 Kudos

Hi,

I am trying to move one particular email from the "InProcess" folder under my Inbox to "UnMatched" folder under my Inbox. Below is my code. After running it, I am getting the below error message:

'Step GLOBAL.newWorkflow.stRead_MoveMails: Error, [ctx.outlook.mail.move] Failed to move the mail. Type mismatch'

Any help is appreciated. Thanks.

// ----------------------------------------------------------------
//   Step: stRead_MoveMails
// ----------------------------------------------------------------
GLOBAL.step({ stRead_MoveMails: function(ev, sc, st) {
	var rootData = sc.data;
	ctx.workflow('newWorkflow', '0c1b404e-f87c-489a-99d1-e573d75b6400') ;
	ctx.outlook.init();


	var emailAddress = ctx.outlook.getCurrentUserAddress();
	ctx.log("emailAddress = " + emailAddress);


	var inProcessfolder = ctx.outlook.folder.getFolder({folderPath : '\\\\'+emailAddress+'\\Inbox\\InProcess'});
 	var unMatchedFolder = ctx.outlook.folder.getFolder({folderPath : '\\\\'+emailAddress+'\\Inbox\\UnMatched'});
	ctx.log("inProcessfolder = " + inProcessfolder);
	ctx.log("unMatchedFolder = " + unMatchedFolder);
	
	// Move from InProcess to UnMatched
	var mails = [];
	ctx.outlook.mail.resetMailCollection();
	ctx.outlook.mail.search({filter : "urn:schemas:httpmail:subject like ''",
         					 maxRow : 100,
				 			 folderName	: inProcessfolder});


	// Retrieves the result of search.
	mails = ctx.outlook.mail.getFilteredTable();
	ctx.log("mails.length:: " +mails.length);


  if (mails.length)
	{


  	// Build the working mails list by retrieving the detail of each mail.
  	for (var i = 0; i< mails.length; i++)
		{
     	ctx.outlook.mail.retrieveMail({EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']});
 		}
		
		ctx.log("ctx.outlook.mail.getCollectionLength():: " +ctx.outlook.mail.getCollectionLength());


    for (var k = 0; k< ctx.outlook.mail.getCollectionLength(); k++)
		{
    	ctx.log("---------------------------------------------------------");
      ctx.log("Mail no:: " + k);
      ctx.log("Subject:: " + ctx.outlook.mail.getSubject(k));
			ctx.log("StoreID:: " + mails[k]['StoreID']);
			ctx.log("EntryID:: " + mails[k]['EntryID']);
			ctx.log("MessageID:: " +ctx.outlook.mail.getMessageId(k));
      ctx.log("---------------------------------------------------------");


			ctx.outlook.mail.move(k,
						{
						  defaultFolder : inProcessfolder,
						  folderName    : unMatchedFolder,
						  storeID		: mails[k]['StoreID']
						});
    }
	}
  ctx.outlook.end();


	sc.endStep(); // end Scenario
	return;
}});

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member717738
Participant
0 Kudos

Hi Suvendu,

When using move activity, defaultFolder is constant and must be "inbox" folderId or folderPath or folderName.

Br,

Thousif.

suvendub98
Explorer
0 Kudos

Thanks Thousif.