что возвращает doc.isresponse?
использование родительского unid должно быть в порядке. Тем не менее
==> Установить parent = db.GetDocumentByUNID ("doc. $ Ref")
недействительно, должно было быть:
if doc.hasItem("$Ref") then
Set parent = db.GetDocumentByUNID(doc.~$Ref(0))
end if
или
if doc.hasItem("$Ref") then
Set parent = db.GetDocumentByUNID(doc.getItemValue("$Ref")(0))
end if