Results 1 to 8 of 8

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

  1. #1
    Join Date
    May 2007
    Posts
    36

    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 !

  2. #2
    Join Date
    Aug 2005
    Posts
    186

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

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

  3. #3
    Join Date
    Aug 2005
    Posts
    186

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    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 > 0)
    {
    ASCopyableMessageBox d = new ASCopyableMessageBox(sbErrors.ToString());
    d.ShowDialog();
    d.Dispose();
    }

    MessageBox.Show("Done!");

    }
    Attached Files Attached Files
    Last edited by AyaNova Support; 10-30-2013 at 09:13 AM. Reason: forgot to comment out the status setting line

  4. #4
    Join Date
    May 2007
    Posts
    36

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    Hi John,

    thanks, it works a treat.

  5. #5
    Join Date
    Aug 2005
    Posts
    186

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    Good to hear!

    Cheers!

  6. #6
    Join Date
    Feb 2013
    Posts
    1

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    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 ?

  7. #7
    Join Date
    Aug 2005
    Posts
    186

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    Quote Originally Posted by nexus6 View Post
    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.

  8. #8
    Join Date
    May 2007
    Posts
    36

    Re: Set Jobs in list to Service Completed, Closed and Wokorder Status to the Global C

    Quote Originally Posted by nexus6 View Post
    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 ?
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •