logo

Scripts for working with documents on a contractor page

This article provides examples of scripts for working with documents on a contractor page.

Scripts with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.

Context variables:

context.Contractor - Contractor-type variable
context.Contractor2 - Contractor-type variable
context.Document - Document type variable

1. Script for adding a document to a contractor page:
Namespace:

using EleWise.ELMA.API;
Script:
var att = PublicAPI.CRM.Objects.CRMAttachment.Create();
att.Contractor = context.Contractor;
att.Documents.Add(context.Document);
att.Save();

2. Script for deleting a company's documents:

Script:

var links = PublicAPI.CRM.Objects.CRMAttachment.Filter().Contractor(context.Contractor).Find();
links.ForEach(l =>{PublicAPI.CRM.Objects.CRMAttachment.Delete(l);});


3. Script for moving documents from the page of the company, to which they are bound, to another company:

Script:

var links = PublicAPI.CRM.Objects.CRMAttachment.Filter().Contractor(context.Contractor).Find().ToList();
links.ForEach(l => {l.Contractor = context.Contractor2;});

Scripts without PublicAPI

List of context variables:

Company1 - Contractor-type variable
Company2 - Contractor-type variable
Document - Document-type variable

For the scripts to work correctly, add the following assemblies:

EleWise.ELMA.CRM;
EleWise.ELMA.Documents;
EleWise.ELMA.Documents.Docflow;

Namespaces:

using EleWise.ELMA.CRM;
using EleWise.ELMA.CRM.Managers;
using EleWise.ELMA.CRM.Models;
using EleWise.ELMA.Documents;
using EleWise.ELMA.Documents.Docflow;
using EleWise.ELMA.Model.Services;
1. Script for adding a document to the contractor page:
 
var att = CrmAttachmentManager.Instance.Create(); // creating a link
att.Contractor = context.Company1; // identify a contractor
att.Documents.Add(context.Document); // add a document
att.Save(); // save the binding
2. Script for deleting a company's documents:
//search bindings for specific companies
var links = CrmAttachmentManager.Instance.Find(l => l.Contractor == context.Company1);
//delete bindings with documents
links.ForEach(l => {
    CrmAttachmentManager.Instance.Delete(l); });
 
3. Script for moving documents from the page of the company, to which they are bound, to another company:
//search bindings for specific companies
var links = CrmAttachmentManager.Instance.Find(l => l.Contractor == context.Company1);
//move the found bindings to another contractor
links.ForEach(l => {
    l.Contractor = context.Company2;});}