using System; using System.Collections.Generic; using System.Linq; using Comindware.Data.Entity; using Comindware.TeamNetwork.Api.Data.UserCommands; using Comindware.TeamNetwork.Api.Data; class Script {     public static UserCommandResult Main(UserCommandContext userCommandContext, Comindware.Entities entities)     { List Photo_1_Images = new List(); List Table_1_Data = new List(); List Table_2_Data = new List(); var data_ = Api.TeamNetwork.ObjectService.GetPropertyValues( userCommandContext.ObjectIds, // getting an array of one or multiple record IDs new[] { "Photo_1_Atr", // the system name of an Image attribute "Table_1_Atr", // the system name of a Record attribute "Table_2_Atr" // the system name of a Record attribute }); Dictionary data = data_.FirstOrDefault().Value; } foreach (byte[] _Image in getImages("Photo_1_Atr", data)) { var temp = new IMG             { Image_data = _Image,             }; Photo_1_Images.Add(temp); } var Table_IdS = getterListSTR("Table_1_Atr", data); foreach (string Table_Id in Table_IdS) { var Table_Data = GetData(Table_Id); string Faсtor_ = getByRef("Title", getString("Faсtor", Table_Data)); // getting the "Title" attribute value by reference via the "Factor" record attribute string Parameter_ = getByRef("Title", getString("Parameter", Table_Data)); // getting the "Title" attribute value by reference via the "Parameter" record attribute string Value_ = getNumber("Value", Table_Data); var temp = new TBL_1             { Factor = Factor_, Parameter = Parameter_, Value = Value_,             };             Table_1_Data.Add(temp); } Table_IdS = getterListSTR("Table_2_Atr", data); foreach (string Table_Id in Table_IdS) { var Table_Data = GetData(Table_Id); var Responsible_ = Api.Base.AccountService.Get(getString("Responsible", Table_Data)); // getting the "Responsible" Account attribute value (account ID) string Date_ = getString("Date", Table_Data); if (DateTime.TryParse(Date_, out var temp_Date)) { Date_ = temp_Date.ToString("dd.MM.yyyy HH:mm"); } var temp = new TBL_2             { Destination = getString("Destination", Table_Data), Order = getNumber("Order", Table_Data), Date = Date_, Responsible = Responsible_.FullName, // getting the responsible persons's full name             };             Table_2_Data.Add(temp); } var dataToExport = new RESULT { Table_1 = Table_1_Data, Table_2 = Table_2_Data, Photo_1 = Photo_1_Images, };         var res = Api.TeamNetwork.ObjectAppExportService.ExecuteWordExportTemplate(userCommandContext.DocumentTemplateId, dataToExport, true);         var result = new UserCommandResult         {             Success = true,             Commited = true,             File=new UserCommandFileResult(){                 Content = res,                 Name = userCommandContext.ExportAsPdf ? "File" + ".pdf" : userCommandContext.FileName + ".docx",                 Type = userCommandContext.ExportAsPdf ? "PDF" : "Word"             },             ResultType = UserCommandResultType.Notificate,             Messages = new[]             {                 new UserCommandMessage                 {                     Severity = SeverityLevel.Normal,                     Text = "Document is ready"                 }             }         };         return result;     } public static string getString(string key, IDictionary dictionary = null) { if (dictionary == null || key == null) { return null; } if (dictionary.TryGetValue(key, out var result)) { if (result == null) return null; return result.ToString(); } else { return null; } } public static string getNumber(string key, IDictionary dictionary = null) { if (dictionary == null || key == null) { return null; } if (dictionary.TryGetValue(key, out var result)) { string result_STR = "-"; if (result == null) return null; if (float.TryParse(result.ToString(), out float result_NUM)) { result_STR = result_NUM.ToString(); } return result_STR; } else { return null; } } public static string getByRef(string key, string objectId = null) { if (objectId == null || objectId.Contains("account") || objectId == "tempID") { return null; } var container = Api.TeamNetwork.ObjectAppService.GetByObject(objectId); var result = Api.TeamNetwork.ObjectService.GetWithAlias(container.Alias, objectId); return getString(key, result); } public static List getImages(string key, IDictionary dictionary = null) { List listImages = new List(); if (dictionary == null || key == null) { return listImages; } if (dictionary.TryGetValue(key, out var result)) { if (result == null) { return listImages; } try { var documentsList = (object[])result; foreach (var documentId in documentsList) { string FileName = (Api.TeamNetwork.DocumentService.GetContent((string)documentId)).Name; if (FileName.EndsWith("png") || FileName.EndsWith("PNG") || FileName.EndsWith("jpeg") || FileName.EndsWith("jpg") || FileName.EndsWith("JPG")) { byte[] content = (Api.TeamNetwork.DocumentService.GetContent((string)documentId)).Data; listImages.Add(content); } } } catch { try { string FileName = (Api.TeamNetwork.DocumentService.GetContent((string)result)).Name; if (FileName.EndsWith("png") || FileName.EndsWith("PNG") || FileName.EndsWith("jpeg") || FileName.EndsWith("jpg") || FileName.EndsWith("JPG")) { byte[] content = (Api.TeamNetwork.DocumentService.GetContent((string)result)).Data; listImages.Add(content); } } catch {} } return listImages; } else { return listImages; } } public static IList getterListSTR(string key, IDictionary dictionary = null) { var result = new List(); if (dictionary != null && key != null) { if (dictionary.TryGetValue(key, out var objectData)) { var objectDataArray = objectData as object[]; foreach (var singlObject in objectDataArray) { if (singlObject == null) continue; result.Add(singlObject.ToString()); } } } return result; } public static IDictionary GetData(string objectId = null) { if (objectId == null || objectId.Contains("account") || objectId == "tempID") { return null; } var container = Api.TeamNetwork.ObjectAppService.GetByObject(objectId); var result = Api.TeamNetwork.ObjectService.GetWithAlias(container.Alias, objectId); return result; } } public class IMG { public byte[] Image_data { get; set; } } public class TBL_1 { public string Factor { get; set; } public string Parameter { get; set; } public string Value { get; set; } } public class TBL_2 { public string Destination { get; set; } public string Order { get; set; } public string Date { get; set; } public string Responsible { get; set; } } public class RESULT { public List Photo_1 { get; set; } public List Table_1 { get; set; } public List Table_2 { get; set; } }