Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint 2013 create multiple columns using REST API.

$
0
0

Dear All,

How to create multiple columns using REST API.

I am trying following code. But some times it is giving error or some times it is creating all columns.

Could any one please tell me how to resolve this issue ?

It is giving error: 

{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\\"SP.AppContextSite(@target)/web/Lists/getbytitle(wow)/fields\\\" is not valid.\"}}}","status":400,"statusText":"Bad Request"}

Code:

createListColumns(2, "HMEmpID", "HM Employee ID")

         // Create a new custom list columns
function createListColumns(fieldType, fieldInternalName, fieldDisplayName)
{
var listName = document.getElementById("inputCreateList").value;

$.ajax(
       {  
           url: appweburl + "/_api/SP.AppContextSite(@target)/web/Lists/getbytitle("+ listName +")/fields?@target='" + hostweburl + "'", 
           type: "POST",
           data: JSON.stringify({
               '__metadata': { 'type': 'SP.Field' }, 'FieldTypeKind': fieldType,
               'InternalName': fieldInternalName, 'Title': fieldDisplayName
//'Group': fieldGroup, 'Required': fieldRequired, 'Hidden': fieldHidden
           }),
           headers: {
               "accept": "application/json;odata=verbose",
               "content-type": "application/json;odata=verbose",
               "X-RequestDigest": $("#__REQUESTDIGEST").val()
           },
           success: function (data) {
               //var d = JSON.parse(data.body);
           },
           error: function (err) {
               alert(JSON.stringify(err));
           }


       }) 
}

Thanks,

Harish Patil


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>