Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

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));
}
});  

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>

Wednesday, November 16, 2016

Checking selected value in all dropdowns using jquery


Below code works if you have multiple drop downs where you want to check the selected value in all drop downs  in the form and see if this value is selected already, if selected then will show an alert message and change the selected value of that particular drop down


Add the "OnChange" in dropdown events as this onchange="ChkCurrent(this);
where 'id' is current value dropdown
 function ChkCurrent(id) {   
            var ddlValues = new Array();
            $("[id*='ddlstsCurrM']").each(function (i) {
                if ($(this).val()== 1) {
                    ddlValues.push($(this).val());
                }

            });
            if (ddlValues.length > 1)
            {
                alert("This value has been already selected");
                var ddlid ="#"+id.id;
                $(ddlid).val('0');

            }
        }

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

Ad