Moving documents in a script
This article describes different ways of moving documents using scripts.
Moving a document from one folder to another
To move a document from one folder to another, you need to change the Folder attribute. Write a new value to it, which has to have the Folder type.
Script without PublicAPI
In the script below the context.Document context variable stores the document, and in the context.NewFolder variable a new folder for the document is selected (this variable has the Folder type).
For the script to work correctly, add the following assemblies:
EleWise.ELMA.Documents;
EleWise.ELMA.Documents.Docflow;
Namespaces:
using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
context.Document.Folder = context.NewFolder;
context.Document.Save();
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here
context.Document - Document type variable
context.Folder - Folder type variable
Namespace:
context.Folder - Folder type variable
Namespace:
using EleWise.ELMA.API;
PublicAPI.Docflow.Document.Move(context.Document, context.Folder, true);
Moving all the documents from the selected folder
Script without using PublicAPI
In this example, the context.old_folder context variable contains the folder to move the documents from and the context.new_folder context variable contains the folder to move the documents to.
Script text:
var filter = new DocumentFilter(); //create a filter for selecting documents from a specific folder
filter.Folder = context.old_folder; //set a filtering parameter
var docs = EntityManager<Document>.Instance.Find(filter, null).ToList();
docs.ForEach(d =>{
d.Folder = context.new_folder; //replace the folder
});
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here
using EleWise.ELMA.API;
using EleWise.ELMA.Extensions;
Script text:
var docs = PublicAPI.Docflow.Document.Filter().Folder(context.old_folder).Find();
docs.ForEach(d =>
{
d.Folder = context.new_folder; //replace the folder
});
Moving a document to a folder with a specific name
Script without using PublicAPI
In the example, a document is moved to the folder, whose name corresponds to the name of a category from the document record card. To execute the script, the document must be registered and the folder with the specified name must exist in the system.
var regkard = RegistrationCardManager.Instance.Get(d => d.Document == context.Document);//find the document record card
var folder = FolderManager.Instance.Get(f => f.Name == regkard.Depository.ToString());//find the folder with the category name in the record card. The folder name must be unique
context.Document.Folder = (Folder)folder;//move the document to the found folder
context.Document.Save();
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here
Add namespaces:
using EleWise.ELMA.API;
using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
Script text:
var regkard = RegistrationCardManager.Instance.Get(d => d.Document == context.Document);
var folder = FolderManager.Instance.Get(f => f.Name == regkard.Depository.ToString());
PublicAPI.Docflow.Document.Move(context.Document, (Folder)folder, true);