1

I have a SharePoint Online, 2013 setup. I want to create some functionality on the Document Set Welcome page using Metadata found in the content type.

I've managed to find the "Status" column, but I cannot figure out how to get the Created By column. Below is my working code for getting the Current User, as well as the Status.

<script type="text/javascript" src="./Content/Scripts/jQuery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="./Content/Scripts/jQuery/jquery.SPServices.min.js"></script>
<script type="text/javascript">
    $(function() {
        var CurrentUser = $().SPServices.SPGetCurrentUser();
        var query = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type=\"int\">" + getQString('ID') + "</Value></Eq></Where></Query>";

        $().SPServices({
            operation: "GetListItems",
            async: false,
            webURL: $().SPServices.SPGetCurrentSite(),
            listName: "Documents",
            CAMLViewFields: "<ViewFields Properties='True' />",
            CAMLQuery: query,
            completefunc: function (xData, Status) {
                $(xData.responseXML).SPFilterNode("z:row").each(function () {
                        //alert($(this).attr("ows_Title"));
                        alert($(this).attr("ows_Status"));
                });
            }
        });
    });
    function getQString(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.search);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
</script>

Is there a way to get the Created By column on the client side? I would then be using that value to see if they are the current user.

0

I overlooked the ows_Author value that was available.

This gives me the name of the Author, which will work in my situation. I can get the name of the current user:

var CurrentUser = $().SPServices.SPGetCurrentUser({fieldName: "Title", debug: false});

I can parse the name from the ows_Author

var CreatedBy = $(this).attr("ows_Author").substr($(this).attr("ows_Author").indexOf("#") + 1);

This works for my scenario, but could be problematic if there are two people with the same name.

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.