I have a problem in JSOM code for SharePoint. Below is the description:

When I try to fetch get_createdBy from FileVersion object it returns SP.User object and when I try to fetch user title or loginName ( .get_title() or .get_loginName() ) from SP.User object I get an error that Title nor loginName is not initialize. Below is my code without createdBy and is working fine with no errors and I am able to get all other details from a FileVersion object except createdBy. Any help would be appreciated.

var totalVersions = 0;
var versionDetailsCounter = 0;

function getVersionHistory() {
    var fileVersions = clientContext.get_web().getFileByServerRelativeUrl(_spPageContextInfo.serverRequestPath).get_versions();

    clientContext.executeQueryAsync(Function.createDelegate(this, function () { onGetVersionHistorySuccess(fileVersions); }), onFail);

function onGetVersionHistorySuccess(fileVersions) {
    var objlistVersionEnumerator = fileVersions.getEnumerator();
    totalVersions = fileVersions.get_count();        
    vTableHtml = "";

    while (objlistVersionEnumerator.moveNext()) {
        var vItem = objlistVersionEnumerator.get_current();
        vTableHtml += "<tr> <td>" + vItem.get_versionLabel() + "</td> <td>" + formatDate(vItem.get_created(), 2) + "</td> <td>" + vItem.get_checkInComment() + "</td> </tr>";

    if (totalVersions === versionDetailsCounter) {
        if (vTableHtml) {
            vTableHtml = "<div id='lblVersionHistory'><h5><strong>Version History</strong></h5></div><table class='table'><thead><tr><th>Version No.</th><th>Modified</th><th>Comments</th></tr></thead><tbody>" + vTableHtml + "</tbody></table>";
        } else {
            vTableHtml = "Version history not available.";
  • how about vItem.get_item("Author").get_lookupValue() ? – Gautam Sheth Mar 8 '18 at 5:38
  • Error: Uncaught TypeError: vItem.get_item is not a function – Dharam Padia Mar 8 '18 at 6:10
  • When I check for vItem.isPropertyAvailable("Created") it returns true and when I check for vItem.isPropertyAvailable("CreatedBy") it returns false. – Dharam Padia Mar 8 '18 at 6:58

You have to include the extra props you need on the load:

clientContext.load(fileVersions, "Include(CreatedBy)");

Since you are using other props too, you'll need those in the include:

clientContext.load(fileVersions, "Include(CreatedBy,VersionLabel, Created, CheckInComment)");

You can reduce the size of the data returned from the query if you specify the load to only include the data you use:

clientContext.load(fileVersions, "Include(CreatedBy.LoginName,VersionLabel, Created, CheckInComment)");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.