StratusForms icon indicating copy to clipboard operation
StratusForms copied to clipboard

How to display Author field

Open rtonerii opened this issue 6 years ago • 2 comments

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

rtonerii avatar Feb 13 '19 19:02 rtonerii

I'd be interested in this, too.

ckaisercc avatar Feb 14 '19 10:02 ckaisercc

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]);
		}
	}
}

gebeauvoir avatar Feb 26 '19 21:02 gebeauvoir