Question

On the display form, I have added a CEWP which has some text. I want to append the list item ID at the end of the text. How can this be done?

Note: Don't have access to SP Designer

Was it helpful?

Solution

Add one of the two scripts below in the source editor of the CEWP:

To display the ID in the first row:

<script type="text/javascript">
//
// Item ID in DispForm.aspx and EditForm.aspx
// Feedback and questions: Christophe@PathToSharePoint.com
//
function DisplayItemID()
{
var regex = new RegExp("[\\?&]"+"ID"+"=([^&#]*)");
var qs = regex.exec(window.location.href);
var TD1 = document.createElement("TD");
TD1.className = "ms-formlabel";
TD1.innerHTML = "<h3 class='ms-standardheader'>Issue ID</h3>";
var TD2 = document.createElement("TD");
TD2.className = "ms-formbody";
TD2.innerHTML = qs[1];
var IdRow = document.createElement("TR");
IdRow.appendChild(TD1);
IdRow.appendChild(TD2);
var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
ItemBody.insertBefore(IdRow,ItemBody.firstChild);
}

_spBodyOnLoadFunctionNames.push("DisplayItemID");
</script>

To display the ID in the last row:

<script type="text/javascript">
//
// Item ID in DispForm.aspx and EditForm.aspx
// Feedback and questions: Christophe@PathToSharePoint.com
//
function DisplayItemID()
{
var regex = new RegExp("[\\?&]"+"ID"+"=([^&#]*)");
var qs = regex.exec(window.location.href);
var TD1 = document.createElement("TD");
TD1.className = "ms-formlabel";
TD1.innerHTML = "<h3 class='ms-standardheader'>Issue ID</h3>";
var TD2 = document.createElement("TD");
TD2.className = "ms-formbody";
TD2.innerHTML = qs[1];
var IdRow = document.createElement("TR");
IdRow.appendChild(TD1);
IdRow.appendChild(TD2);
var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
ItemBody.appendChild(IdRow);
}

_spBodyOnLoadFunctionNames.push("DisplayItemID");
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top