Thursday, March 28, 2019

SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details


If you see this kind of error, make sure that is because the value which you are passing doesnt match with the data type present in the sharepoint list column

make sure what ever you are sending to sharepoint list matches the column data type, to figure out which column is causing the error, remove one by one column/filed in the item which you are passing or else you can check the error.responseText in error

Creating a new task in SharePoint list using CSOM/Rest API


var fieldUserValues = new Array();
      fieldUserValues.push(userId);              //userid is ID of user

$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Project Tasks')/Items",
type: 'POST',
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "POST"
},
data: JSON.stringify({
__metadata: {
type: "SP.Data.Project_x0020_TasksListItem"
},
Title: taskName,             
StartDate: taskStartDate,
DueDate: taskDueDate,
PercentComplete: percentageComplete, //percentage complete should be integer
AssignedToId: { "results": fieldUserValues }
}),
success: function(data) {
alert('Item created successfully!');
},
error: function(error) {
alert(JSON.stringify(error));
}
 });

Wednesday, March 27, 2019

Getting tasks and sub-tasks from task list using SharePoint 2013/SP online and rest API


var fullurl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Project%20Tasks')/items?$select=*,ParentID/Id,Predecessors,Predecessors/Id&$expand=ParentID,Predecessors";
    $.ajax 
({ 
url: fullurl, 
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
var items = data.d.results.length;
if(items > 0) 

var tasks = data.d.results; 

jsonObj = [];
var mainTasks = [], subTasks = [];
$.each(tasks, function (index, task) {
if(task.ParentID.Id) {
item = {}
item ["ParentID"] = task.ParentID.Id
item ["Title"] = task.Title
item ["Priority"] = task.Priority
item ["DueDate"] = task.DueDate
item ["StartDate"] = task.StartDate
item ["PercentComplete"] = task.PercentComplete
item ["Status"] = task.Status
subTasks.push(item);
} else {
item = {}
var startdate = $.datepicker.formatDate( "dd-mm-yy", new Date(task.StartDate));
var duedate = $.datepicker.formatDate( "dd-mm-yy", new Date(task.DueDate));
item ["ID"] = task.Id
item ["Title"] = task.Title
item ["Priority"] = task.Priority
item ["DueDate"] = duedate
item ["StartDate"] = startdate
item ["PercentComplete"] = task.PercentComplete
item ["Status"] = task.Status
mainTasks.push(item);
}
});
},
error: function (error) {
alert(JSON.stringify(error));
}
});  

Saturday, March 23, 2019

CSS targeting for IE10 and IE11

use the below media query for IE 10 and 11

@media screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none) { 
` % add classes here %
}

example:

@media screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none) { 
.lblpagetitle
{
margin-bottom:3%;
margin-top:-2.5%;
}
}

Thursday, March 7, 2019

Reading data from a CSV file using JQuery

Here is a quick code snippet on how to read data from a .CSV file using JQuery/Javascript
download papaparse.min.js and add the link to your code before running the below code

<html lang="en">
 <head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="data/papaparse.min.js"></script>
  <title>Read CSV file using JavaScript and HTML5 </title>
  <style>
.pdfobject-container { height: 500px;}
.pdfobject { border: 1px solid #666; }
  </style>
</head>
<body>
  <div class="container" style="padding:10px 10px;">
    <h1>Read CSV file using JavaScript</h1>
<div id="header"></div>
<div class="well">
<div class="row">
<div class="form-inline">
<div class="form-group">
  <label for="files">Upload a CSV formatted file:</label>
  <input type="file" id="files"  class="form-control" accept=".csv" required />
</div>
<div class="form-group">
<button type="submit" id="submit-file" class="btn btn-primary">Upload File</button>
</div>
</div>
</div>
<div class="row"

<div class="row" id="parsed_csv_list">
</div>
</div>
</div>
<div id="footer"></div>
  </div>
</body>
</html>
<script type="text/javascript">
  $(document).ready(function(){
    $('#submit-file').on("click",function(e){
e.preventDefault();
$('#files').parse({
config: {
complete: displayHTMLTable,
},
before: function(file, inputElem)
{
//console.log("Parsing file...", file);
},
error: function(err, file)
{
//console.log("ERROR:", err, file);
},
complete: function()
{
//console.log("Done with all files");
}
});
    });

function displayHTMLTable(results){
var table = "<table class='table'>";
var data = results.data;

for(i=0;i<data.length;i++){
table+= "<tr>";
var row = data[i];
var cells = row.join(",").split(",");

for(j=0;j<cells.length;j++){
table+= "<td>";
table+= cells[j];
table+= "</th>";
}
table+= "</tr>";
}
table+= "</table>";
$("#parsed_csv_list").html(table);
}
  });
</script>

SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details If y...

Ad