Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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' }
share|improve this question
    
as per your program you can only pass one parameter in metadata? –  SharePointer Apr 7 at 10:26

1 Answer 1

up vote 4 down vote accepted

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'}};
share|improve this answer
    
Or simply URL: "http://www.google.com, Google" –  Arsalan Adam Khatri Apr 7 at 11:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.