Pankaj Kore

Pankaj Kore

  • NA
  • 3
  • 652

Create a folder and add field values to it using javascript

Jun 4 2017 3:01 AM

0down votefavorite

I have created a simple form on SP site, on the submission of which a folder with entered name in the form would get created in the desired doc library.Library has some custom columns such as Description,Start Date, End Date.Now I want to enhance the code such that the custom column values pertaining to this folder should get inserted at the time of creation.

<form >
<TABLE>
<TR>
<TD>Project Name</TD>
<TD>
<INPUT TYPE="TEXT" ID="project_name" NAME="name" SIZE="30">
</TD>
</TR>
<TR>
<TD>Description</TD>
<TD><INPUT TYPE="TEXT" ID="Description" NAME="email" SIZE="30"></TD>
</TR>
</TABLE>

</form>

<div><button onclick=" retrieveWebSite()">Create</button></div>
<div id="displayDiv"></div>
<script type="text/javascript">
function retrieveWebSite() {
var clientContext;
var oWebsite;
var oList;
var itemCreateInfo;
var folderName = document.getElementById('project_name').value;
clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("Project");

itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName(folderName);
this.oListItem = oList.addItem(itemCreateInfo);
this.oListItem.update();

clientContext.load(this.oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);

function successHandler() {
alert('A new project folder has been created successfully.Please check Existing Project');
}

function errorHandler() {
alert('Some Error occured');
}
}
</script>