context.getUrl()
gives you only the current URL. It doesn't contain the documentId because you create a new document in your case.
You are looking for an URL that will open current document with current XPage. You can get it with:
var thisdoc = docSource.getDocument(true);
var url = facesContext.getExternalContext().getRequest().getRequestURL().toString() +
"?action=editDocument&documentId=" + thisdoc.getUniversalID());