system.util.invokeLater or alternative function in global script?

My suggestion for you is to pseudo code before you begin. It helps a ton.

Semantically speaking, what are the steps you need to accomplish? And write them down under one function you will end up calling.

def doesImportantStuff(data):
    step_one_results = stepOnef(data)
    step_two_results = stepTwo(data, step_one_results)
    step_three_results = stepThree(data, step_two_results)

etc. Except name your functions in a way that when you read them again (and you will) you get at least a sense of what is going on.

For example, for my forms I tend to have their own scripting module and they each have a create function. The create function for adding a new customer in my module looks like

TABLENAME='customers'

def create(newData):
	"""
	Creating a new customer.
	Args:
		newData: data dictionary of all the db columns required
	Returns:
		(success, idx) - boolean, int
            boolean - true if successfully saved to database, false if not verified with checker function
            int - id of new record in database from getKey=1
	"""
	validateNew(newData)
	modifyNew(newData)
	sanitizeNew(newData)
	result, newIdx = new_db.query.insert(newData, TABLENAME, getKey=1)
	handleAliases(aliases, newIdx)
	pathDictionary = createFilePath(newIdx)
	success = new_db.query.update(pathDictionary, tableName,newIdx)
	createDirectory(pathDictionary)
	initializeHelpThread(newIdx,userId,pathDictionary)
	templates.navTree.refreshData()
	return result, newIdx 

You don’t need to know what all my functions are, but you can see to create a customer I take the data, I validate it against some criteria, modify it, sanitize it, and then insert it. I do something else with handleAliases, which I can’t recall but if I go to that function I’ll see some function documentation that explains what it does (which sidenote you should document your functions), looks like I create a file path, update the database, create the directory based on the filepath, start a forum thread (something my application has), and then refresh the GUI for the user, before returning the results.

You will need to read code more than you write it so take care to write good code.

I like making the function I am going to call first and then underneath writing my other function calls - before I even necessarily write the function. It’s like building the skeleton first, and then after you can read the functions in order and they tell you a sort of story, then go flesh out those functions.

7 Likes