public static int?Execute(CorrigoService service, int woid) { var action = new WoLastAction { WorkOrderId = woid, LastAction = new WoActionLog { Id = 5 }, EmergencyReason = new WoActionReasonLookup { Id = 1289 }, Reason = new WoActionReasonLookup { Id = 1289 }, BillStatus = BillStatus.NotBilled, Invoice = new Invoice { Id = 269 }, BilledTotal = new MoneyValue { Value = 156m, CurrencyTypeId = CurrencyType.USD }, XNumber = "123" }; //WoLastModificationCommand ? var command = new CreateCommand { Entity = action }; var response = service.Execute(command) as OperationCommandResponse; var printOut = response?.ErrorInfo?.Description; printOut = !string.IsNullOrWhiteSpace(printOut) ? $"{nameof(WoLastAction)} creation failure reason: {printOut}" : $"Successfully created {nameof(WoLastAction)} instance for WorkOrder with id {woid}."; Debug.Print(printOut); return(response?.EntitySpecifier?.Id); }
public static void Execute(CorrigoService service, WoPriority toUpdate) { if (toUpdate == null || service == null) { return; } toUpdate.DisplayAs = "-"; //Label toUpdate.DueInMinutes = 3; //Complete mins. toUpdate.IsEmergency = true; //Escalate toUpdate.RespondInMinutes = 5; //Responce mins. Console.WriteLine($"Update WoPriority with id={toUpdate.Id.ToString()}"); var resultUpdate = service.Execute(new UpdateCommand { Entity = toUpdate, PropertySet = new PropertySet { Properties = new[] { "DisplayAs", "IsEmergency", "RespondInMinutes", "DueInMinutes" } } }); if (resultUpdate == null) { Console.WriteLine("Update of WoPriority failed"); return; } if (resultUpdate.ErrorInfo != null && !string.IsNullOrEmpty(resultUpdate.ErrorInfo.Description)) { Console.WriteLine(resultUpdate.ErrorInfo.Description); Console.WriteLine("Update of WoPriority failed"); return; } Console.WriteLine("WoPriority is updated"); }
// WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable public static void Execute(CorrigoService service, WoLastAction toUpdate) { if (toUpdate == null || service == null) { return; } toUpdate.BilledTotal = new MoneyValue { Value = 0, CurrencyTypeId = CurrencyType.USD }; Console.WriteLine(); Console.WriteLine($"Updating WoLastAction with id={toUpdate.Id}"); var resultUpdate = service.Execute(new UpdateCommand { Entity = toUpdate, PropertySet = new PropertySet { Properties = new[] { "BilledTotal" } } }); if (resultUpdate == null) { Console.WriteLine("Update of WoLastAction failed"); return; } if (resultUpdate.ErrorInfo != null && !string.IsNullOrEmpty(resultUpdate.ErrorInfo.Description)) { Console.WriteLine(resultUpdate.ErrorInfo.Description); Console.WriteLine("Update of WoLastAction failed"); return; } Console.WriteLine("WoLastAction is updated"); }
public static void Execute(CorrigoService service, Address2 toUpdate) { if (toUpdate == null || service == null) { return; } toUpdate.Street = (toUpdate.Street ?? "") + "."; toUpdate.Street2 = "Test street2."; toUpdate.City = "Test city by wsdk"; Console.WriteLine(); Console.WriteLine($"Updating Address2 with id={toUpdate.Id.ToString()}"); var resultUpdate = service.Execute(new UpdateCommand { Entity = toUpdate, PropertySet = new PropertySet { Properties = new[] { "Street", "Street2", "City" } } }); if (resultUpdate == null) { Console.WriteLine("Update of Address2 failed"); return; } if (resultUpdate.ErrorInfo != null && !string.IsNullOrEmpty(resultUpdate.ErrorInfo.Description)) { Console.WriteLine(resultUpdate.ErrorInfo.Description); Console.WriteLine("Update of Address2 failed"); return; } Console.WriteLine("Address2 is updated"); }
public static void Execute(CorrigoService service, Employee toUpdate) { if (toUpdate == null || service == null) { return; } toUpdate.Instructions = string.Concat("Instructions updated by WSDK at ", $"{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}"); var specialties = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.Specialty, PropertySet = new AllProperties(), Criteria = new FilterExpression { Conditions = new ConditionExpression[] { new ConditionExpression { PropertyName = "Id", Operator = ConditionOperator.GreaterThan, Values = new object[] { 0 } } }, FilterOperator = LogicalOperator.Or }, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, }); Specialty specialty = (specialties != null && specialties.Length > 0) ? specialties[0] as Specialty : null; if (specialty != null) { LinkUserAndSpecialty userAndSpecialty = new LinkUserAndSpecialty { SpecialtyId = specialty.Id, UserId = toUpdate.Id }; toUpdate.Specialties = new LinkUserAndSpecialty[] { userAndSpecialty }; } Console.WriteLine($"Updating Employee with id={toUpdate.Id.ToString()}"); var resultUpdate = service.Execute(new UpdateCommand { Entity = toUpdate, PropertySet = new PropertySet { Properties = new[] { "Instructions", "Specialties.*" } } }); if (resultUpdate == null) { Console.WriteLine("Update of Employee failed"); return; } if (resultUpdate.ErrorInfo != null && !string.IsNullOrEmpty(resultUpdate.ErrorInfo.Description)) { Console.WriteLine(resultUpdate.ErrorInfo.Description); Console.WriteLine("Update of Employee failed"); return; } Console.WriteLine("Employee is updated"); }
private static WorkOrder CreateWorkOrder(CorrigoService service) { var workZone = (WorkZone)service.Retrieve( new EntitySpecifier { Id = 28, EntityType = EntityType.WorkZone }, new PropertySet { Properties = new[] { "Id", "TimeZone" } }); var workOrder = new WorkOrder { Items = new[] { new WoItem { Asset = new Location { Id = 173 }, Task = new Task { Id = 14096 } } }, Customer = new Customer { Id = 14 }, WorkZone = workZone, TimeZone = workZone.TimeZone, //WorkOrderCost = workOrderCost, Priority = new WoPriority { Id = 2 }, MainAsset = new Location { Id = 173 }, SubType = new WorkOrderType { Id = 4 }, StatusId = WorkOrderStatus.New, ContactName = "Somerset Moehm", ContactAddress = new ContactInfo { Address = "San Francisco", ActorTypeId = ActorType.Asset, AddrTypeId = ContactAddrType.Contact }, TypeCategory = WOType.Request, //required }; var command = new WoCreateCommand { WorkOrder = workOrder, Comment = string.Empty, ComputeAssignment = true, ComputeSchedule = false, SkipBillToLogic = false }; var response = service.Execute(command) as WoActionResponse; return(response?.Wo); }
public static WorkOrderCostId Execute(CorrigoService service) { var workOrder = CreateWorkOrder(service); workOrder.WorkOrderCost.CustomerNte.Value = 28.98m; workOrder.WorkOrderCost.CustomerNte.CurrencyTypeId = CurrencyType.USD; //workOrder.WorkOrderCost.CostState = CostState.Pending; workOrder.WorkOrderCost.BillingRule = BillingRule.NotBilled; //workOrder.WorkOrderCost.BillToType = BillToType.Customer; //workOrder.WorkOrderCost.BillingAccount = new BillingAccount //{ //}; //workOrder.WorkOrderCost.ChargeCode = new ChargeCodeLookup { Code = "some charge code", Id = 0 }; //workOrder.WorkOrderCost.TaxStatus = TaxValidationStatus.Success; //workOrder.WorkOrderCost.Items = new[] { new FinancialItem //{ // CostCategoryId = CostCategory.Services, // Quantity = 10, // Amount = 56.23m, //} }; //var workOrderCost = new WorkOrderCost //{ // CustomerNte = 28.98m, // CostState = CostState.Pending, // BillToType = BillToType.Customer, // //ChargeCode = new ChargeCodeLookup // //{ // // DisplayAs = "display as charge code", // // Code = "some charge code", // //}, // //Items = new[] // // { // // new FinancialItem // // { // // CostCategoryId = CostCategory.Services, // // Quantity = 10, // // Amount = 56.23m, // // } // // } //}; var command = new UpdateCommand { Entity = workOrder, //PropertySet = new PropertySet { Properties = new[] { "WorkOrderCost.*" } } PropertySet = new PropertySet { Properties = new[] { "WorkOrderCost.CustomerNte", "WorkOrderCost.BillingRule", //"WorkOrderCost.ChargeCode.*", //"WorkOrderCost.Items.*", } } }; var response = service.Execute(command) as OperationCommandResponse; var woCostId = response?.EntitySpecifier?.Id ?? 0; Debug.Print(response?.ErrorInfo?.Description ?? $"Successfully created {nameof(WorkOrder.WorkOrderCost)} with id '{woCostId}'" + $" for WorkOrder with id '{workOrder.Id}'"); return(new WorkOrderCostId { WoId = workOrder.Id, CostId = woCostId }); }
public static Employee Execute(CorrigoService service) { Debug.Print("Creating Employee"); Console.WriteLine("Creating Employee"); Random rnd = new Random(); int randNmbr = rnd.Next(0, 25); char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); string suffix = String.Concat("_", alpha[randNmbr], randNmbr.ToString()); var toCreate = new Employee { FirstName = "FN" + suffix, LastName = "LN" + suffix, DisplayAs = "FN.LN_" + suffix + $".ByWSDK.{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}", Username = "******" + suffix, Password = "******" + suffix + "!Hey-Ya!", ActorTypeId = ActorType.Employee, WonServiceRadius = 1, Role = new Role { Id = 1 }, Number = "Number" + suffix, FederalId = "FederalId" + suffix, ExternalId = "ExternalId" + suffix }; var resultData = service.Execute(new CreateCommand { Entity = toCreate }); if (resultData == null) { Debug.Print("Creation of new Employee failed"); Console.WriteLine("Creation of new Employee failed"); Console.WriteLine(); return(null); } var commandResponse = resultData as OperationCommandResponse; int?id = (commandResponse != null && commandResponse.EntitySpecifier != null) ? commandResponse.EntitySpecifier.Id : null; if (id.HasValue && resultData.ErrorInfo == null) { toCreate.Id = id.Value; Debug.Print($"Created new Employee with Id={id.ToString()}"); Console.WriteLine($"Created new Employee with Id={id.ToString()}"); Console.WriteLine(); return(toCreate); } Debug.Print("Creation of new Employee failed"); Console.WriteLine("Creation of new Employee failed"); Console.WriteLine(); if (resultData.ErrorInfo != null && !string.IsNullOrEmpty(resultData.ErrorInfo.Description)) { Debug.Print(resultData.ErrorInfo.Description); Console.WriteLine(resultData.ErrorInfo.Description); } return(null); }
public static WorkOrder Execute(CorrigoService service, bool computeAssignment, bool computeSchedule) { //WorkOrder requires WorkZone for its creation //default time zone is UTC-12, therefore provide WorkOrder with time zone from WorkZone var workZone = (WorkZone)service.Retrieve( new EntitySpecifier { Id = WorkZoneId, EntityType = EntityType.WorkZone }, new PropertySet { Properties = new[] { "Id", "TimeZone" } }); var workOrder = new WorkOrder { Items = new[] //required { new WoItem { Asset = new Location { Id = SpaceUnitSubAssetId }, //required Task = new Task { Id = TaskId } //required } }, Customer = new Customer { Id = CustomerId }, //required //WorkZone = workZone, //TimeZone = workZone.TimeZone, //Priority = new WoPriority { Id = 1 }, //MainAsset = new Location { Id = SpaceUnitAssetId }, SubType = new WorkOrderType { Id = SubTypeId }, //required //StatusId = WorkOrderStatus.New, //ContactName = "John Smith", ContactAddress = new ContactInfo //required for request at least { Address = "San Francisco", //required //ActorTypeId = ActorType.Asset, AddrTypeId = ContactAddrType.Contact //required }, TypeCategory = WOType.Request, //required //CreatedDateUtc = DateTime.UtcNow, //DueDateUtc = DateTime.UtcNow, //DtUtcOnSiteBy = DateTime.UtcNow, //DtScheduledStart = DateTime.UtcNow, //ScheduledStartUtc = DateTime.UtcNow, }; var command = new WoCreateCommand { WorkOrder = workOrder, Comment = string.Empty, ComputeAssignment = computeAssignment, ComputeSchedule = computeSchedule, SkipBillToLogic = false }; var response = service.Execute(command) as WoActionResponse; if (response.ErrorInfo != null) { Debug.Print(response.ErrorInfo.Description); } return(response?.Wo); }
public static Document Execute(CorrigoService service, DocumentCreateParams createParams) { if (service == null || createParams == null) { return(null); } Console.WriteLine(); Debug.Print("Creating Document"); Console.WriteLine("Creating Document"); //Get latest WO CorrigoEntity[] latestWO = WoActionLogExamples.GetLatestWOs(service, 1); if (latestWO.Length != 1) { Console.WriteLine("Can not create Document because no existing Work Order was found"); return(null); } //Get document types var documentTypes = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.DocumentType, PropertySet = new AllProperties(), }); var docType = documentTypes.Where(t => ((DocumentType)t).DisplayAs == createParams.DocType).SingleOrDefault(); var toCreate = new Document { ActorId = latestWO[0].Id, ActorTypeId = ActorType.WO, Description = createParams.Description, Title = createParams.Title, DocType = new DocumentType { Id = docType.Id }, MimeType = createParams.MimeType, StorageTypeId = createParams.IsLink? DocumentStorageType.URL : DocumentStorageType.Local }; toCreate.DocUrl = createParams.IsLink ? toCreate.Description : toCreate.Title; if (!string.IsNullOrEmpty(createParams.FileName)) { toCreate.Blob = new Blob { FileName = createParams.FileName, Body = createParams.Body }; } var resultData = service.Execute(new CreateCommand { Entity = toCreate }); if (resultData == null) { Debug.Print("Creation of new Document failed"); Console.WriteLine("Creation of new Document failed"); Console.WriteLine(); return(null); } var commandResponse = resultData as OperationCommandResponse; int?id = (commandResponse != null && commandResponse.EntitySpecifier != null) ? commandResponse.EntitySpecifier.Id : null; if (id.HasValue && resultData.ErrorInfo == null) { toCreate.Id = id.Value; Debug.Print($"Created new Document with Id={id.ToString()}"); Console.WriteLine($"Created new Document with Id={id.ToString()}"); Console.WriteLine(); return(toCreate); } Debug.Print("Creation of new Document failed"); Console.WriteLine("Creation of new Document failed"); Console.WriteLine(); if (resultData.ErrorInfo != null && !string.IsNullOrEmpty(resultData.ErrorInfo.Description)) { Debug.Print(resultData.ErrorInfo.Description); Console.WriteLine(resultData.ErrorInfo.Description); } return(null); }
/// <summary> /// Get Custom Field Descriptor by specified field name, domain(entity) object type, and Custom Field Type. /// When Custom Field Descriptor by specified parameters is not found, the new descriptor is going to be created. /// </summary> /// <param name="service"></param> /// <param name="fieldName"></param> /// <param name="actorType"></param> /// <param name="cfType"></param> /// <returns>CustomFieldDescriptor</returns> private static CustomFieldDescriptor GetCustomFieldDescriptor(CorrigoService service, string fieldName, ActorType actorType, CfType cfType) { var list = service.RetrieveMultiple( new QueryExpression { Count = 1, EntityType = EntityType.CustomFieldDescriptor, PropertySet = new PropertySet { Properties = new string[] { "*" } }, Criteria = new FilterExpression { Conditions = new ConditionExpression[] { new ConditionExpression { PropertyName = "Type", Operator = ConditionOperator.Equal, Values = new object[] { cfType } }, new ConditionExpression { PropertyName = "ActorTypeId", Operator = ConditionOperator.Equal, Values = new object[] { actorType } }, new ConditionExpression { PropertyName = "Name", Operator = ConditionOperator.Equal, Values = new object[] { fieldName } }, new ConditionExpression { PropertyName = "IsRemoved", Operator = ConditionOperator.Equal, Values = new object[] { false } } }, FilterOperator = LogicalOperator.And }, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, }); if (list.Any()) { return(list[0] as CustomFieldDescriptor); } var entity = new CustomFieldDescriptor { ActorTypeId = actorType, Name = fieldName, Type = cfType }; var command = new CreateCommand { Entity = entity }; var response = service.Execute(command) as OperationCommandResponse; entity.Id = response?.EntitySpecifier?.Id ?? 0; return(entity); }
/// <summary> /// Create Location /// </summary> /// <param name="corrigoService"></param> /// <returns></returns> public static Location CreateLocation(CorrigoService corrigoService) { #region Get Ids for Location required fields: Model, WorkZoneAsset Id // // Retrieve Asset Id // int workZoneAssetId = (corrigoService.RetrieveMultiple( new QueryByProperty { Count = 1, EntityType = EntityType.WorkZone, PropertySet = new PropertySet { Properties = new string[] { "Asset.Id", } }, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, //Conditions = new PropertyValuePair[0] }).FirstOrDefault() as WorkZone)?.Asset.Id ?? 0; if (workZoneAssetId == 0) { return(null); } int modelId = corrigoService.RetrieveMultiple( new QueryExpression { EntityType = EntityType.Model, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, Count = 1 }).FirstOrDefault()?.Id ?? 0; if (modelId == 0) { return(null); } #endregion var asset = new Location { Name = $"Test location {DateTime.Now}", Address = new Address2 { TypeId = StreetAddrType.Primary, Street = $"Test Street {DateTime.Now}" }, ModelId = modelId, Orphan = true, TypeId = AssetType.Building, ParentId = workZoneAssetId, IsTemplate = false }; var command = new CreateCommand { Entity = asset }; var response = corrigoService.Execute(command) as OperationCommandResponse; var id = response?.EntitySpecifier.Id ?? 0; Console.WriteLine(response?.ErrorInfo?.Description ?? $"Successfully created Location with id {id}"); //Console.ReadKey(); var location = corrigoService.Retrieve( new EntitySpecifier { EntityType = EntityType.Location, Id = id }, new PropertySet { Properties = new string[] { "*", "Address.*", } }) as Location; return(location); }
/// <summary> /// WO Use Case1: Create WO for Customer /// Operation: Execute /// Command: Create Work Order /// Specify required fields /// /// Additional fields to specify: /// Customer Id, /// Contact: Name, Address, Phone /// Comment = "Sample Work Order generated via Web Services for Customer" /// Compute Schedule = true /// Compute Assignment = true /// </summary> /// <param name="corrigoService"></param> /// <param name="customer"></param>/// public static WorkOrder CreateWorkOrderForCustomer(CorrigoService corrigoService, Customer customer) { if (customer == null) { return(null); } // // Get Ids for Asset, Task, Subtype which will be used for composition of required WO properties // from the existing Work Order. // var requiredFields = GetWorkOrderWithRequiredFields(corrigoService); // Specify required fields: WorkOrder newWorkOrder = new WorkOrder { Items = new[] { new WoItem { Asset = new Location { Id = requiredFields.Items[0].Asset.Id }, Task = new Task { Id = requiredFields.Items[0].Task.Id } } }, Customer = new Customer { Id = customer.Id }, SubType = new WorkOrderType { Id = 4 }, //we need Request when it's simple reactive WO with a custumer /* * ID SubType * 1 Basic * 2 PMRM * 3 Turn * 4 Request * 5 Project */ ContactAddress = new ContactInfo { Address = "1(877) 267-7440, 8245 SW Tualatin Sherwood Road Tualatin, OR 97062", AddrTypeId = ContactAddrType.Contact }, TypeCategory = WOType.Request, }; // Additional fields to specify: newWorkOrder.ContactName = "Contact Name"; var command = new WoCreateCommand { WorkOrder = newWorkOrder, Comment = "Sample Work Order generated via Web Services for Customer", ComputeAssignment = true, ComputeSchedule = true, }; var response = corrigoService.Execute(command) as WoActionResponse; if (response.ErrorInfo != null) { Console.WriteLine(response.ErrorInfo.Description); } else if (response?.Wo != null) { Console.WriteLine($"Created new Work Order with Id={response.Wo.Id}"); } //Console.ReadKey(); return(response?.Wo); }
public static WorkZone Execute(CorrigoService service) { Console.WriteLine(); Debug.Print("Creating WorkZone"); Console.WriteLine("Creating WorkZone"); // // Get Asset Template Id by its name. // Template name can be spotted by navigation Url: https://v91.qa.corrigo.com/corpnet/assets/templatemanager.aspx // string assetTemplateName = "SK_WrokZoneTemplate"; var assetTemplates = service.RetrieveMultiple( new QueryByProperty { Count = 1, EntityType = EntityType.AssetTemplate, PropertySet = new PropertySet { Properties = new string[] { "Id", } }, Conditions = new[] { new PropertyValuePair { PropertyName = "DisplayAs", Value = assetTemplateName }, }, }); WorkZone toCreate = new WorkZone { DisplayAs = $"Test {DateTime.Now}", Number = $"Test {DateTime.Now}", WoNumberPrefix = Guid.NewGuid().ToString().Split('-')[0], TimeZone = 4, //(GMT-08:00) Pacific Time (US & Canada) AutoAssignEnabled = true, DefaultAccess = PTEType.Unknown }; var resultData = service.Execute(new WorkZoneCreateCommand { AssetTemplateId = assetTemplates[0].Id, WorkZone = toCreate, SkipDefaultSettings = false }); if (resultData == null) { Debug.Print("Creation of new WorkZone failed"); Console.WriteLine("Creation of new WorkZone failed"); Console.WriteLine(); return(null); } var commandResponse = resultData as WorkZoneCommandResponse; int?id = commandResponse?.WorkZone?.Id; if (id.HasValue && resultData.ErrorInfo == null) { toCreate.Id = id.Value; Debug.Print($"Created new WorkZone with Id={id}"); Console.WriteLine($"Created new WorkZone with Id={id}"); Console.WriteLine(); return(toCreate); } Debug.Print("Creation of new WorkZone failed"); Console.WriteLine("Creation of new WorkZone failed"); Console.WriteLine(); if (resultData.ErrorInfo != null && !string.IsNullOrEmpty(resultData.ErrorInfo.Description)) { Debug.Print(resultData.ErrorInfo.Description); Console.WriteLine(resultData.ErrorInfo.Description); } return(null); }
public static EntitySpecifier[] Execute(CorrigoService service, int woid) { var wo = Read.Execute(service, woid); int startIndex = wo.Items.Max(i => i.SortOrderIdx); List <WoItem> items = new List <WoItem>(wo.Items); items.Add( new WoItem { WorkOrderId = woid, SortOrderIdx = startIndex + 1, //Disposition = new Disposition(), AssetLocation = "location 1", Asset = new Location { Id = wo.Items[0].Asset.Id }, Task = new Task { Id = wo.Items[0].Task.Id }, Comment = "comment 1" }); items.Add( new WoItem { WorkOrderId = woid, SortOrderIdx = startIndex + 2, //Disposition = new Disposition //{ // DisplayAs = "disposition 2", // IsCompleted = false, // IsCancelled = false, // OnCreate = false, // OnComplete = true, // OnCancel = false //}, AssetLocation = "location 2", Asset = new Location { Id = wo.Items[0].Asset.Id }, Task = new Task { Id = wo.Items[0].Task.Id }, Comment = "comment 2" }); wo.Items = items.ToArray(); // wo.Items = new[] //{ // new WoItem // { // WorkOrderId = woid, // SortOrderIdx = startIndex + 2, // Disposition = new Disposition // { // DisplayAs = "disposition 2", // IsCompleted = false, // IsCancelled = false, // OnCreate = false, // OnComplete = true, // OnCancel = false // }, // AssetLocation = "location 2", // Asset = new Location {Id = wo.Items[0].Asset.Id}, // Task = new Task {Id = wo.Items[0].Task.Id}, // Comment = "comment 2" // }, // new WoItem // { // WorkOrderId = woid, // SortOrderIdx = startIndex + 1, // Disposition = new Disposition(), // AssetLocation = "location 1", // Asset = new Location {Id = wo.Items[0].Asset.Id}, // Task = new Task {Id = wo.Items[0].Task.Id}, // Comment = "comment 1" // } //}; var command = new UpdateCommand { Entity = wo, PropertySet = new PropertySet { Properties = new[] { nameof(WorkOrder.Items) + ".*" } } }; var response = service.Execute(command) as OperationCommandResponse; Debug.Print(response.ErrorInfo?.Description ?? "Successfully created items for a work order"); return(response.NestedEntitiesOperationResults.Select(r => r.EntitySpecifier).ToArray()); }
public static Task Execute(CorrigoService service) { Console.WriteLine(); Debug.Print("Creating Task"); Console.WriteLine("Creating Task"); #region Get Ids for Task required fields: latest existing Model, Priority, Speciality, GLAccount var modelList = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.Model, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, Count = 1 }); if (modelList == null || modelList.Length == 0) { Debug.Print("Creation of new Task failed - no existing Model is found"); Console.WriteLine("Creation of new Task failed - no existing Model is found"); return(null); } var priorityList = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.WoPriority, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, Count = 1 }); if (priorityList == null || priorityList.Length == 0) { Debug.Print("Creation of new Task failed - no existing priority is found"); Console.WriteLine("Creation of new Task failed - no existing priority is found"); return(null); } var specialtyList = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.Specialty, Orders = new[] { new OrderExpression { OrderType = OrderType.Descending, PropertyName = "Id" } }, Count = 1 }); if (specialtyList == null || specialtyList.Length == 0) { Debug.Print("Creation of new Task failed - no existing specialty is found"); Console.WriteLine("Creation of new Task failed - no existing specialty is found"); return(null); } var accountList = service.RetrieveMultiple( new QueryExpression { EntityType = EntityType.GLAccount, Orders = new[] { new OrderExpression { OrderType = OrderType.Ascending, PropertyName = "Id" } }, Count = 1 }); //if (accountList == null || accountList.Length == 0) //{ // Debug.Print("Creation of new Task failed - no existing GLaccount is found"); // Console.WriteLine("Creation of new Task failed - no existing GLaccount is found"); // return null; //} #endregion string timeStamp = $".ByWSDK.{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}"; var toCreate = new Task { //All fields below are required ModelId = modelList[0].Id, Priority = new WoPriority { Id = priorityList[0].Id }, Specialty = new Specialty { Id = specialtyList[0].Id }, //GlAccount = ((GLAccount)accountList[0]).DisplayAs, Preventive = true, //Type is required DisplayAs = "Test Task" + timeStamp, Instructions = "-", SelfHelpContent = "-", Number = "TN" + timeStamp }; var resultData = service.Execute(new CreateCommand { Entity = toCreate }); if (resultData == null) { Debug.Print("Creation of new Task failed"); Console.WriteLine("Creation of new Task failed"); Console.WriteLine(); return(null); } var commandResponse = resultData as OperationCommandResponse; int?id = (commandResponse != null && commandResponse.EntitySpecifier != null) ? commandResponse.EntitySpecifier.Id : null; if (id.HasValue && resultData.ErrorInfo == null) { toCreate.Id = id.Value; Debug.Print($"Created new Task with Id={id.ToString()}"); Console.WriteLine($"Created new Task with Id={id.ToString()}"); Console.WriteLine(); return(toCreate); } Debug.Print("Creation of new Task failed"); Console.WriteLine("Creation of new Task failed"); Console.WriteLine(); if (resultData.ErrorInfo != null && !string.IsNullOrEmpty(resultData.ErrorInfo.Description)) { Debug.Print(resultData.ErrorInfo.Description); Console.WriteLine(resultData.ErrorInfo.Description); } return(null); }