2

I have a list with a title and a url. I'm trying to add a new url using this function

function addListItem(url, listname, metadata, success, failure) {

    // Prepping our update
    var item = $.extend({
        "__metadata": { "type": getListItemType(listname)}
    }, metadata);

    // Executing our add
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            success(data); // Returns the newly created list item information
        },
        error: function (data) {
            failure(data);
        }
    });

}

I can set the title using this metadata item:

metadata = { Title: 'myTitle' }

But how can I set the url in this context? This doesn't work:

metadata = { Title: 'myTitle', Url: 'http://myspurl' }
1
  • as per your program you can only pass one parameter in metadata? Commented Apr 7, 2014 at 10:26

1 Answer 1

5

In order to set Url Field value in SharePoint REST specify the following JSON object:

URL: {Url: 'http://www.microsoft.com',Description: 'MSFT'}

where URL is the name of a field.

Example

var metadata = { Title: 'myTitle', URL: {Url: 'http://www.microsoft.com',Description: 'MSFT'}};
1
  • Or simply URL: "http://www.google.com, Google" Commented Apr 7, 2014 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.