This project has moved and is read-only. For the latest updates, please go here.

GetListItems Multi-Value Lookup field

Aug 15, 2014 at 8:58 PM

My team has created a custom calendar for clients to keep track of events on with the data being pulled from a calendar list. Let's say on the Monthly view, a user clicks on the event for August 1 at 9 AM. When the user clicks, a dialog will appear that will give more information on the event besides the Title and the Start Time on the calendar. The extra fields in the dialog are pulled from the Calendar list using "GetListItems".

Here's my issue. One of the fields is the Rooms that will be used for the event. The field is a multi select lookup field and when I go to grab the list items, it of course returns the room Title with the ID of the item and the ";#" at the beginning. Since there are multiple rooms, the string ends up looking like this: "1;#Room 1;#2;#Room 2;#4;#Room 7".

What I need, is to somehow return the name of the rooms without the ID and the ";#" string in it. Keep in mind that sometimes, a room could have a number or "#" associated with it so getting rid of all those type of characters isn't an option.

Is there so Sp Service or jQuery function I don't know about that can help? Any Ideas?
Aug 16, 2014 at 3:19 AM
Give this a shot:
"1;#Room 1;#2;#Room 2;#4;#Room 7".split(";#").filter(function(v, idx, arr) {
    return idx % 2 !== 0;
Keep in mind that this works with IE9+ but could easily be polyfilled for old IE. For more resources, check out MDN, it's great!
Aug 18, 2014 at 1:40 PM
Thanks for the quick response! I am fairly new to Javascript and SP Services and I don't understand this function. How would it work with my code?

$(this).attr("ows_Resource"); is where I am grabbing the rooms at.
//Callback when the event div is clicked on in the calendar that give event details in a dialog.
function EventDetails_Click(div) {

    //Event varaibles
    var eventTitle; var eventDescription; var originalEventStart; var originalEventEnd; var eventRooms; var eventBuildings;

    var eventID = $(div).parent().attr("event-id");

    //Grabs the list item with the ID in the event a tag href
    $().SPServices({ operation: "GetListItems", listName: "Calendar", CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + eventID + "</Value></Eq></Where></Query>",

        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                eventTitle = $(this).attr("ows_Title");
                eventDescription = $(this).attr("ows_Description");
                originalEventStart = $(this).attr("ows_EventDate");
                originalEventEnd = $(this).attr("ows_EndDate");
                eventRooms = $(this).attr("ows_Resource");
                eventBuildings = $(this).attr("ows_Building");

            //Blank description
            if (eventDescription == null) { eventDescription = "No Description." };

            //Event start and end day and time
            var eventStart = $, "M/d/yyyy h:mm a");
            var eventEnd = $, "M/d/yyyy h:mm a");

            //Bootstrap modal dialog that will give the event details
            $("#modalHeader").html("Event Details for " + eventTitle);
            $("#modalBody").html("<strong>Event ID:</strong> <span id='spanEventId'>" + eventID + "</span><br><br><strong>Title:</strong> " + eventTitle + "<br><br><strong>Description:</strong> " + eventDescription + "<br><br><strong>Days/Times:</strong> " + eventStart + " <strong>to</strong> " + eventEnd + "<br><br><strong>Room(s):</strong> " + eventRooms + "<br><br><strong>Building(s):</strong> " + eventBuildings);
Aug 20, 2014 at 3:24 AM
What Matt is showing you is how to split the values into an array and then take every other value which excludes the ID values.

You'd most likely use it like this:
eventRooms = $(this).attr("ows_Resource").split(";#").filter(function(idx) {
    return idx % 2 !== 0;
This will give you an array of the room names.