Getting document type default folder for using in scripts

When creating a document in a script (https://kb.elma-bpm.com/article-3603.html), you have to specify the folder, to which the document will be saved.

To get the folder, selected as the default folder in the document type settings, you can use the following script:

var metadata = (DocumentMetadata)MetadataLoader.LoadMetadata(doc.TypeUid);
var profile = DocumentMetadataProfileManager.Instance.LoadByDocumentType(metadata.ImplementationUid);

 if (profile.Folder != null)

 {

       doc.Folder = (Folder)profile.Folder;

}

where doc is the variable with the created/existing document.

Add the following namespaces for this script:

using EleWise.ELMA.Documents.Models;

using EleWise.ELMA.Documents.Managers;

using EleWise.ELMA.Documents.Metadata;

You can add a condition: if the default folder is not selected in the document type, save the document to the My Document folder of a certain user. Example of the script using PublicAPI: 

var metadata = (DocumentMetadata)MetadataLoader.LoadMetadata(doc.TypeUid);

var profile = DocumentMetadataProfileManager.Instance.LoadByDocumentType(metadata.ImplementationUid);

 if (profile.Folder != null)

 {

        doc.Folder = (Folder)profile.Folder;

 }

 else

 {

      var user = PublicAPI.Portal.Security.User.GetCurrentUser();

      var folderMy = PublicAPI.Docflow.Folder.GetMyDocumentFolder(user);

      doc.Folder = (Folder)folderMy;

}

 Add the following namespaces for this script:

using EleWise.ELMA.API;

using EleWise.ELMA.Documents.Models;

using EleWise.ELMA.Documents.Managers;

using EleWise.ELMA.Documents.Metadata;