logo

Creating a deal with a script

This is an example of a script for creating a deal in the CRM section.

Script with PublicAPI

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

Context variable:

context.Contractor - variable of the Contractor type

Namespace:

using EleWise.ELMA.API;

Script:

var sale = PublicAPI.CRM.Sale.Create();
sale.Name = "Deal name";
sale.SaleType = PublicAPI.CRM.Sale.LoadSaleTypeOrNull("Deal #1"); //Identify the deal type by its name
sale.Contractor=context.Contractor;
sale.Author = PublicAPI.Portal.Security.User.GetCurrentUser(); //author - current executor
sale.Responsible = PublicAPI.Portal.Security.User.GetCurrentUser(); //responsible - current executor
sale.Save();

Script without PublicAPI

The script includes the following context variables:
context.Contractor - variable of the Contractor type
context.DealType - variable of the Deal Type type

For the script to work, add the following assembly:

Elewise.ELMA.CRM

Namespaces:

using EleWise.ELMA.CRM;
using EleWise.ELMA.CRM.Managers;
using EleWise.ELMA.CRM.Models;
using EleWise.ELMA.Extensions;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Model.Mappings;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Security.Services;
using EleWise.ELMA.Services;
using EleWise.ELMA.Configuration;
Script:
var sale=SaleManager.Instance.Create();
sale.Name="Deal name";
sale.SaleType= context.DealType;
sale.Contractor=context.Contractor;
sale.Author=AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>(); //author - current executor
sale.Responsible=AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>(); //responsible - current executor
sale.Save();