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

Add value to lookup column in SharePoint list

$
0
0

I am trying to add value to look up field through code

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
var siteUrl = 'https://team.abc.com/sites/XYZ/';

function createListItem() {

var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Test Projects');

var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);

oListItem.set_item("Project_ID_x003a_ID","490");     //lookup
oListItem.set_item("Time_x002d_ProjectType","NA");     //choice
oListItem.set_item("SiteURL","https://team.abc.com/sites/XYZ/490/pages/home.aspx");//text
oListItem.set_item("ProjectManager","shristy.priyadarshi@abc.com");//person and group

oListItem.update();

clientContext.load(oListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

alert('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
</head>
<body>
<button type="submit" onclick="createListItem()">Submit</button>
</body>
</html>

And getting this error, attached.

Please let me know how to add value to look up field manually



Viewing all articles
Browse latest Browse all 7589

Trending Articles



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