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); }
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); }
/// <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); }