Help with macro adding outline hyperlinks in Writer

I am having trouble with a macro that adds Hyperlinks. Here is a basic example of adding a link.

	dim args1(4) as new
	args1(0).Name = "Hyperlink.Text"
	args1(0).Value = "Dentistry"
	args1(1).Name = "Hyperlink.URL"
	args1(1).Value = "#11.20.46.Dentistry|outline"
	args1(2).Name = "Hyperlink.Target"
	args1(2).Value = ""
	args1(3).Name = "Hyperlink.Name"
	args1(3).Value = ""
	args1(4).Name = "Hyperlink.Type"
	args1(4).Value = 1
	dispatcher.executeDispatch(document, ".uno:SetHyperlink", "", 0, args1())

That’s simple enough but I need to scan the document’s outline and pull out certain links and use them in arg1(1).value.

How do I do that in a Basic script? btw using LO 7.1 on Ubuntu