REST API and Drop Down

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

10 Dec 2014

Hi there,

I'm still new to all this.

Been trying to get a successful result from the REST API (part 1) then use that knowledge in combination with other code (part 2) to piece together how to populate a drop down via the results of an API call in spform or just in general.


Part 1:

Have a div with the id message.

function doGet()

{

var call = jQuery.ajax({

url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/lists('<guid is here>')/items?$select=*",

type: "GET",

dataType: "json",

headers: {

Accept: "application/json;odata=verbose"

}

});


call.done(function (data,textStatus, jqXHR) {

var message = jQuery("#message");

message.text("X");

jQuery.each(data.d.results, function (index, item) {

message.append("<br/>");

message.append(item.Id);

});

});

call.fail(function (jqXHR,textStatus,errorThrown){

alert("Error retrieving: " + errorThrown);


});


}

As for populating the drop down with an array here's the code I was able to get working in part 2.

Part 2:

There's an HTML box select element called selectMonth inside spForms.

var items = new Array("January","February","March","April","May","June","July","August","September","October","November","December");


var list = document.getElementById("selectMonth");

for(var i in items) {

list.add(new Option(items, items));

}


If anyone has any advice on getting the REST API to work in part 1 I think I can stitch things together to populate the drop down list. So far I've been frustrated.

Thanks to anyone who can help.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

11 Dec 2014

Hi,

Have you tried our another solution Cross-site Lookup that uses REST api to populate a drop-down control? It allows you to filter and sort the result set, request additional columns, and customize view of the result set.

Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

11 Dec 2014

I saw that, but I know later on I will need to get into some more complex queries once I get up to speed so I'm trying to learn. I might end up trying out your product but for me the task of learning to do it without still remains.

Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

11 Dec 2014

Also I need to do more with the data than just the drop down. I need to use a list on the site collection main site for some validation.

Perhaps you could hint at how I could populate a text field with a single value returned from a REST API call?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

12 Dec 2014

Sure, in the following sample I pre-populate the Title field with the title of the first item from another list (Issues):

Code: Select all

$.getJSON("/_api/web/lists/GetByTitle('Issues')/items", 
    function(items) {
	fd.field('Title').value(items.value[0].Title);
    });

Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

12 Dec 2014

Thanks Dmitry.

Looks like this info may help me take a step or two forward.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests