Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global Close

Hi,

must admit could be pushing the envelope of help here !!

The aim is to select a list of workorders in a view then set them to Service Completed = True, Closed = True, and set the Workorder status to the Global Work order status (thats sets up in Administration - Global Settings).

I am using your Set Client Notification Off AyaScript as a bit of a framework to see how to do it.

I admit my API knowledge is next to nothing and am going through a process of learning.

I believe that Global.WorkorderClosedStatus contains the global closed Status setting.

I am unsure where the overall Workorder Service Completed and Workorder Closed are held.

Also do you have a bit of code that sets the WOrkorder Closed to closed for a list of items please. Once I get the basics I will be able to do the rest myself.

Thanks for the help !

Hi Martin, I’ll get back to you with help on this shortly.

Hey Martin, sorry for the delay, I just got a new computer and everything is a bit catywampus right now.
The script below should do what you want.
I’ve also attached it as a text file in case the forum software messes with it but you should be able to just copy and paste it starting at the //Script… bit below
.
**This script is designed to work with a list of selected service workorders in AyaNova so the AyaScript would be run only from the Service Workorders list.
**And don’t forget to select which workorders are to be updated that are listed in the grid by checkmarking the row selector for the workorder records you specifically want set to Service Completed and Closed.
.
Let me know how it works out for you.

  • John

//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<Guid> 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, just uncomment the following line:
               // 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 &gt; 0)
            {
		ASCopyableMessageBox d = new ASCopyableMessageBox(sbErrors.ToString());
		d.ShowDialog();
    		d.Dispose();
            }

            MessageBox.Show("Done!");

}

Close selected workorders sample script

Hi John,

thanks, it works a treat.

Good to hear!

Cheers!

Hello,

Ayanova returns this error when I try to run the script: Current user not authorized to open a workorder record.
I’m logged with the manager account.
Any idea ?

Hello, the script uses the same API as AyaNova itself so I would recommend you manually try to do the same steps on the same workorder that the error is given on by hand as you may get a more clear error message within AyaNova user interface than the script reports. Anything that happens in the script should happen when doing it manually and vice versa, just the error message may differ.

Are you doing this from the Service Workorder level or something lower (e.g. Service Workorder / Items ). I got caught on this intially ! Try doing it with the Service Work Order Level selected in teh menu.