Finding the parent if it exists and create one if it doesn't

I’m trying to create my first AppleScript for OO. What I want to do is to create an outline that looks something like this

2017-02
    2017-02-23
        stub1
        stub2
        stub3
    2017-02-28
        stub1
        stub2
        stub3
2017-03
    2017-03-02
        stub1
        stub2
        stub3

I’ve managed to create a script that creates these parts

    2017-03-02
        stub1
        stub2
        stub3

but how do I find the correct parent, so for example if I want to add a new day in february how to I find the “2017-02” row, or how do I find out that there is no row with “2017-04”?

I really struggle with Applescript and am just starting to write scripts for OO5, and this does not address everything you want to do, but it does test whether the 2017-04 exists, so maybe it helps a bit.

tell application "OmniOutliner"
	tell front document
		repeat with MyRow in every row
			set cellValue to text of cell 2 of MyRow -- or text of cell "Column name" if mult. named columns
			if cellValue contains "2017-04" then
				display dialog "exists" --other action for creating rows
			else
				display dialog "does not exist" 
			end if
		end repeat
	end tell
end tell

Thanks, I ended up with the handler below which seem to do what I want

on findThisMonth(monthText)
    tell front document of application "OmniOutliner"
        repeat with myRow in (every row whose level is 1)
            if topic of myRow = monthText then
                return myRow
            end if
        end repeat
        return (make new row with properties {topic:monthText} at the end)
    end tell
end findThisMonth

which then can be rewritten as

on findThisMonth(monthText)
    tell front document of application "OmniOutliner"
        set rowsFound to every row whose topic is monthText
        if rowsFound = {} then
            return (make new row with properties {topic:monthText} at the end)
        else
            return item 1 of rowsFound
        end if
    end tell
end findThisMonth

or, if fewer lines of code is the goal

on findThisMonth(monthText)
    tell front document of application "OmniOutliner"
        repeat with myRow in (every row whose topic is monthText)
            return myRow
        end repeat
        return (make new row with properties {topic:monthText} at the end)
    end tell
end findThisMonth