mrackley / StratusForms

Lightweight InfoPath alternative for SharePoint 2007,2010,2013,2016,2019 and Office 365
82 stars 36 forks source link

How to display Author field #43

Open rtonerii opened 5 years ago

rtonerii commented 5 years ago

How do I display a read-only field, such as an author or editor field?

ckaisercc commented 5 years ago

I'd be interested in this, too.

gebeauvoir commented 5 years ago

Not sure if there is a better way to do this but I use SPServices to pull the list item data and set span values (see below). Hope that this helps


function GetStaticItemValues() {
    var itemID = getUrlParameter("ID"); // or formID based on where you are using it
    if(itemID){
        $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: [LIST_NAME],
            CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Author' /><FieldRef Name='Created' /></ViewFields>",
            CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + itemID + "</Value></Eq></Where></Query>",
            completefunc: function (xData, Status) {
                $(xData.responseXML).SPFilterNode("z:row").each(function() {
                    $("#[MY_CREATED_BY_SPAN_ID]").text($(this).attr("ows_Author").split("#").pop());
                    $("#[MY_CREATED_DATE_SPAN_ID]").text( $(this).attr("ows_Created")); //might want to format the date
                });
            }
        });
    }
}

//Get Url parameter matching passed string parameter (sParam)
function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
}