Skip to main content

How do you get a user's name and description from thiertheir ID in the SDL Tridion Anguilla framework

Source Link
Chris Summers
  • 9.1k
  • 1
  • 22
  • 55

How do you get a user's name and description from thier ID in the SDL Tridion Anguilla framework

I have written a GUI extension for SDL Tridion 2011 SP1. The GUI consists of an extra ribbon button and event handler which is triggered when a component is saved.

My event handler is registered as follows:

PowerTools.Commands.ItemCommenting.prototype._execute = function (selection) {
    var item = $display.getItem();
    $evt.addEventHandler(item, "save", this.getDelegate(this._onItemSaved));
    $cme.getCommand("SaveClose")._execute(selection);
};

and the event handler looks like this:

PowerTools.Commands.ItemCommenting.prototype._onItemSaved = function (eventitem) {

    var comment = prompt("Please enter a comment", "");

    $messages.registerNotification("Saving user comments...");

    var commentitemid = eventitem.source.getId();
    var commenterid = eventitem.source.getCreatorId();
    var commenter = $tcm.getItem(commenterid);
    var commentername = commenter.getDescription();
    var commentdate = eventitem.source.getLastModifiedDate();
    var commentversion = eventitem.source.getVersion();

    //Call the service to update 
    PowerTools.Model.Services.AppDataServices.Append("ext:ItemCommenting", commentitemid, "<comment><user>" + commenterid + "</user><message>" + comment + "</message><datetime>" + commentdate + "</datetime><version>" + commentversion + "</version></comment>", null, null, null, false);

};

This is working fine, except that the variable commentername is always undefined. Is there a better approach for getting the name and description of a user?

Additionally, does anyone know if the value returned by eventitem.source.getCreatorId() is actually the Reviser or actually the person who created the item?

Thanks in advance