0

I currently have:

  • A custom SP List
  • A title field and a "user or group" field

I need to use SPServices to look up the user in the list and obtain their name, email and profile picture just by looking up the user or group column.

Once I have that information, I'll build a HTML structure to create a form of "contact card"

Any assistance with this would be greatly appreciated.

Thanks in advance :)

1

I have a similar problem, I decided that's:

  1. Get UserNameAccount by $().SPServices.SPGetCurrentUser
  2. Get with this account item from list by ID
var currentUsername = $().SPServices.SPGetCurrentUser({
    fieldName: "Name"
});

getUserInfoFromSPList(currentUsername); // call function with parameter userAccount

function getUserInfoFromSPList(userAccount) {
$().SPServices({
    webUrl: "http://spdev/",
    operation: "GetListItems",
    async: false,
    listName: "{CBFDE2BF-793C-4C09-AF16-82F69887294E}",
    CAMLQuery: "<Query>" +
                    "<Where>" +
                            "<Eq>" +
                                "<FieldRef Name='UserName' />" +
                                "<Value Type='Text'>" + userAccount + "</Value>" +
                            "</Eq>" +
                       "</Where>" +
               "</Query>",
    CAMLViewFields: "<ViewFields>" +
            "<FieldRef Name='Title' />" +
            "<FieldRef Name='field1' />" + 
            "<FieldRef Name='field2' />" + 
        "</ViewFields>",
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function () {
           someVar = $(this).attr("ows_Title")
           somevar1 = $(this).attr("ows_field1")
           someVar2$(this).attr("ows_field1")
            });
        });
    }
});
}
  • HI Sashko, thanks for responding! - A couple of questions. Does SPGetCurrentUser get the user that's logged in? Does the "WebURL" need to be included? The part i'm mainly confused about is at which point the code is obtaining the details of the user from the list column. Thanks again for your time, hugely appreciated. – Tron Jun 4 '15 at 10:11
  • Sure, The SPGetCurrentUser getting current logged user account like at "SHAREPONT\UserName", instead $().SPServices.SPGetCurrentUser you can use custom username. The "WebURL" use only if you need to specify a list on another site, else this optional. – Sashko Jun 4 '15 at 10:43
  • The function getUserInfoFromSPList(currentUsername) use anytime: load document, click button... Example: $(document).ready(function () { getUserInfoFromSPList(currentUsername) }); – Sashko Jun 4 '15 at 10:43
  • Thanks Sashko. Instead of the current logged in user, how would i obtain the SPName (SHAREPONT\UserName) from an SP list? If I could swap out the current user for users specified in the custom list, I think i should be ok :) – Tron Jun 4 '15 at 10:51
  • You can use specified users for search them in the custom list. You are welcome, glad to help you ;-) – Sashko Jun 4 '15 at 10:58

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.