Forum Discussion
christopher_gillis
9 years agoNew Member
Hello,
When creating a new Method item, you do not need to include a specific call to a 'main' function. When you attach the Method code to a server event, the code will be run whenever that event triggers.
For example, the code in a Method that is attached to an onBeforeUpdate server event of the Part ItemType will run everytime that a Part item is updated by a user.
As in your use case, sometimes it is helpful to break the code down into multiple functions when you have a lot of logic being run in a single server event. As you found, you can include additional functions within a Method item by first closing the primary code with a closing bracket '}' and leaving the closing bracket off of the last helper function you define as seen in the example below.
Innovator inn = this.getInnovator();
Item res = helperFunction(this);
Item secRes = secondHelperFunction(this);
Item lastRes = lastHelperFunction(this);
return this;
}
public Item helperFunction(Item arg) {
// Helper code
return arg;
}
public Item secondHelperFunction(Item arg) {
// Helper code
return arg;
}
public Item lastHelperFunction(Item arg) {
// Helper code
return arg;
In order to get the function in your example to run, you should include a call to it before the first closing bracket:
main();
return this; }
public Item main()
{
Innovator inn = this.getInnovator();
etc.
Chris
____________________________________
Christopher Gillis
Aras Labs Software Engineer