Question

I want to get the User Account ID inside of a 'Person or Group' field in my Display Form:

enter image description here

is it possible?

Was it helpful?

Solution

I wrote a little script to determine your requirement. This actually compares both user names so hopefully that will work for you. The alternative would be to grab the User name from the displayed text instead of querying the list again.

Open your DispForm.aspx in SharePoint designer and add this script in the 'PlaceHolderAdditionalPageHead' section

<script>
    function GetQueryStringParams(sParam)
    {
        var sPageURL = window.location.search.substring(1);
        var sURLVariables = sPageURL.split('&');
        for (var i = 0; i < sURLVariables.length; i++) 
        {
            var sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] == sParam) 
            {
                return sParameterName[1];
            }
        }
    }

    $( document ).ready(function() {        
        //var user = $().SPServices.SPGetCurrentUser();
        var user = $().SPServices.SPGetCurrentUser({
                      fieldName: "Title"
                    });

        var requester;
        var id= GetQueryStringParams('ID');

            $().SPServices({
                operation: 'GetListItems',
                async: false,
                debug: false,
                listName: 'PollVotes',
                CAMLQuery: '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">' + id + '</Value></Eq></Where></Query>',
                completefunc: function (xData, Status) {
                    var xNode = $(xData.responseXML).SPFilterNode("z:row")[0];
                    if (xNode != null)
                    {
                        $(xData.responseXML).SPFilterNode("z:row").each(function () {
                            requester = $(this).attr("ows_Requester");
                        });
                    }
                }
            });

        if(requester.split('#')[1] + " - " + user)
            alert("The Requester equals the Current User");
    });

</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top