How to insert value in Publishing Hyperlink column using Resi API in SharePoint?

I have a "Hyperlink" field type of "Publishing Hyperlink" i want to save data into list using JQuery But this field return an error.

var item = {
        "__metadata": { "type": "SP.Data.ListNameListItem" },
        "Hyperlink": "<a href=\"/Documents/SampleFile.docx\" target=\"_blank\"><IMG src=\"/_layouts/images/icdoc.gif\" alt=\"\">Open [SampleFile.docx] in a new window</a>"
    };

    // 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) {                
            saveSuccess();
            // success(data); // Returns the newly created list item information
        },
        error: function (data) {
            //failure(data);
        }
    });

Error:

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"de-DE","value":"The property 'Hyperlink' does not exist on type 'SP.Data.ListNameListItem'. Make sure to only use property names that are defined by the type."}}}

June 25th, 2015 9:07am

Hi,

In my environment, I created a list named "test123" and a hyperlink field named "hyper", Then I used the Rest API code snippet below to insert value to the hyper link field.

var item = {
   "__metadata": { "type": "SP.Data.Test123ListItem" },
   "Title": "test1",
   "hyper": {
                    '__metadata': { 'type': 'SP.FieldUrlValue' },
                    'Description': 'SP',
                    'Url': 'http://img.25pp.com/uploadfile/soft/images/2014/0629/20140629110548444.jpg'
            },
 };

 $.ajax({
   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('test123')/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) {        
     console.log(data);
   },
   error: function (data) {
     console.log(data);
   }
 });

Thanks

Best Regards

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 3:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics