Search code examples
xpagesxpages-ssjsssjs

Xpages @Author showing 2 Authors


I am using the following SSJS:

var author = @Author().toString();
var str = author.replace("CN=","");
var str2 = str.replace("O=","");
var str3 = str2.replace("[","");
var str4 = str3.replace("]","");

if("" == str4)
    return @Name("[CN]",session.getEffectiveUserName());
else
    return var4;

not the perfect way to do it, but...

Question: Why do I get all the users which edited the document in this field? I only want to show the Author of the document.


Solution

  • You get a list of all users because that's what @Author() returns. Here is the description of the function taken from the online help: "Returns the names of the authors of the current document."

    You can use @Subset() to get the latest author:

    @Subset(@Author(), -1)
    

    and to get the original author:

    @Subset(@Author(), 1)
    

    Use @Name() to format the name. So to only show the common name part of the original author, do this:

    @Name("[CN]",@Subset(@Author(), 1))