AyaScript plugin - Sample scripts

I’m posting the stock scripts that come with the AyaScript plugin here in case anyone needs to refer back to them because they accidentally (or on purpose) :slight_smile: deleted the stock scripts in the AyaScript plugin.

Remember one AyaScriptMain per script, don’t copy and paste all this in one script. :wink:


//Name: zSample - Hello AyaScript!

//ShowInMenuFor: Everywhere

//HandlesAyaNovaTypes: Nothing

//This is a bare minimum script. The comments above are required and the AyaScriptMain method and it’s signature below are required

//the rest is up to you.

public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)

{

MessageBox.Show("Hello from AyaScript!");

}


//Name: zSample - copyable message box

//ShowInMenuFor: Everywhere

//HandlesAyaNovaTypes: Nothing

//This example shows useage of the built in Copyable message box which you can use with your scripts that return a lot of data or log something that

//the end user might want to copy and paste elsewhere

public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)

{

ASCopyableMessageBox d = new ASCopyableMessageBox("This is a copyable message box you can use with your scripts, see source code for details.\rYour text here.\rLine two\rLine three\rLast line!");

d.ShowDialog();

    d.Dispose();

}


//Name: zSample - Single client modify fields

//ShowInMenuFor: Single AyaNova object

//HandlesAyaNovaTypes: Client

//This sample shows how to deal with a single object, in this case a client but the concept is the same for other objects

//For more information on using the AyaNova API see the API reference at http://api.ayanova.com/

//and the “Development / SDK / API” area of the AyaNova support forum at http://forum.ayanova.com/

public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)

{

//Ignore if we don't have an object

if(ayaNovaObject==null || ayaNovaObject is DBNull) return;



Client c=ayaNovaObject as Client;

if (MessageBox.Show("Warning: this will modify the account number and notes fields of current client " + c.Name +

            "\rAre you sure?", "About to modify client", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;

        

c.AccountNumber="123456";

    c.Notes = "These notes were set by AyaScript on " + DateTime.Now.ToString();

}


//Name: zSample - parameter usage

//ShowInMenuFor: Everywhere

//HandlesAyaNovaTypes: Client, HeadOffice, Part, Project, Unit, Vendor, WikiPage, Workorder

public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)

{

    StringBuilder sb = new StringBuilder();

        sb.Append("Script was called with these parameters:\r");

        

        //Was script called from a list form or a single object editing form?

        sb.Append("IsList: ");

        sb.Append(IsList.ToString());

        sb.Append("\r");

  

        //What type of AyaNova RootObjectType was the script called from?

        sb.Append("objectType: ");

        sb.Append(objectType.ToString());

        sb.Append("\r");

    

        //ayaNovaObject parameter  	

        if (ayaNovaObject is DBNull)

            sb.Append("ayaNovaObject: is a DBNull (script was called from main menu)\r");

        else

        {

            sb.Append("ayaNovaObject type: "