Add a submenu to a dynamically created menu item

In my previous thread I asked how to make a dynamically created menubar properly function:

I am now trying to add a submenu to each of these menu items. I have looked up other tutorials online, but I have not been able to figure out how to integrate them into my code.

Here is a portion of how my current code is set up:

	repeat with i from 1 to number of items in mylibrary
		set this_item to item i of mylibrary
		--display dialog this_item
		set thisMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:this_item action:"someAction:" keyEquivalent:"")
		(newMenu's addItem:thisMenuItem)
		(thisMenuItem's setTarget:me) -- required for enabling the menu item
		set dividerCount to dividerCount + 1
		if dividerCount is 4 then
			(newMenu's addItem:(current application's NSMenuItem's separatorItem)) -- add a seperator
			set dividerCount to 0
		end if
	end repeat
	set quitMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:"Quit" action:"showQuit:" keyEquivalent:"")
	StatusItem's setMenu:newMenu
	newMenu's addItem:quitMenuItem
	quitMenuItem's setTarget:me
end makeMenus

How could I make it so each of the menu items has a submenu with a fixed amount of clickable items?

Have a look at the structure of the menus in the main menu bar. You can’t add menu items to other menu items: you add menus to the menu items, and then add menu items to the menu.

Thanks. I was able to add a submenu with the following code:

set subMenu to (current application's (NSMenu's alloc)'s initWithTitle:"instanceOptions")


		set menuElementStatus to (current application's NSMenuItem's alloc()'s initWithTitle:("Status:" & (word 1 of instanceStatus)) action:"copyInfo:" keyEquivalent:"")
		(subMenu's addItem:menuElementStatus)
		(menuElementStatus's setToolTip:instanceStatus)
		(menuElementStatus's setTarget:me)