That would require a snippet, you would call it with an argument &parent=`[*parent*]`, then the snippet would have to get the parent of the given document. Something like
$doc = $modx->getParent($parent);
$gpId = $doc['parent'];
return $gpid;
Or... if you are using 0.9.5, with its DocumentMap, you could use getParentIds and select the second item in the resulting array. I haven’t worked with that feature yet, so I’m not sure how it would go. I’d want to take a look at that array with a print_r() of it. Probably something like this:
$parents = $modx->getParentIds($modx->documentIdentifier);
$grandparent = $parents[1]; // 0 would be parent, 1 would be grandparent, etc...
return $grandparent;
No need for an argument in the snippet call in this case.