//Script created: 2/5/2013 //Name: Close selected workorders //ShowInMenuFor: List of AyaNova objects //HandlesAyaNovaTypes: WorkorderService public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List objectIDList) { //Reserve a place to store any errors during operation System.Text.StringBuilder sbErrors=new StringBuilder(); foreach (Guid i in objectIDList) { //Fetch the workorder object from it's ID and do not place it in the most recently used object list (NoMRU) Workorder w = Workorder.GetItemNoMRU(i); //Already closed? if (w.Closed) continue;//It's already closed so move on to next one //If we're here it's not closed so let's close it.. //SET WORKORDER STATUS //Note: There is no need to set the workorder status to the global settings automatical status on close //as that will be done automatically when you set it to closed=true below, however if for some reason you want to do it //anyway, it would be done here like this: w.WorkorderService.WorkorderStatusID = AyaBizUtils.GlobalSettings.WorkorderClosedStatus; //First set it to service completed as that is a prerequisite to close it w.ServiceCompleted = true; //Now close it. No need to set closed workorder status since it automatically will do it here w.Closed = true; //Make sure there are no broken rules and it can be saved if (w.IsSavable) w.Save();//save it else { //Whups, there were broken rules for some reason so save it to display at the end sbErrors.AppendLine("Workorder " + w.WorkorderService.ServiceNumber.ToString() + " is not saveable:"); sbErrors.AppendLine(w.BrokenRulesText); sbErrors.AppendLine("****************************************"); } } //display errors if necessary if (sbErrors.Length > 0) { ASCopyableMessageBox d = new ASCopyableMessageBox(sbErrors.ToString()); d.ShowDialog(); d.Dispose(); } MessageBox.Show("Done!"); }