Creating/removing a link between documents in a script

This article provides an example of a script for creating or removing a link between two documents.
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Context variables:

context.Doc1 - variable of the Document type
context.Doc2 - variable of the Document type

Namespace:

using EleWise.ELMA.API;
 

Script for linking documents:

var new_link = PublicAPI.Docflow.Document.CreateLink(context.Doc1, context.Doc2, "Link name"); //create a link between documents
 

Script for deleting a link between documents:

//search links for specific documents 
var links = PublicAPI.Docflow.Objects.DocumentLink.Find(String.Format("Document= {0} and LinkedDocument = {1}", context.Doc1.Id, context.Doc2.Id)).ToList(); 
//remove the found links
links.ForEach(l => { PublicAPI.Docflow.Objects.DocumentLink.Delete(l); });
//search links
links = PublicAPI.Docflow.Objects.DocumentLink.Find(String.Format("Document = {0} and LinkedDocument= {1}", context.Doc2.Id, context.Doc1.Id)).ToList();
//remove the found links
links.ForEach(l => { PublicAPI.Docflow.Objects.DocumentLink.Delete(l); });