How to change null value to empty string in Sharepoint custom script? Here is my code.

$(document).ready(function() { 

    function getUserListItems() {  
        var currentUser = _spPageContextInfo.userId;


        async: true,  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('BUGSList')/items?$Select=Title,Requester_x0020_Name,Department,Title0,Priority,Description,Comments,Issue_x0020_Status,Assigned_x0020_To,Author/ID&$filter=substringof('"+ currentUser +"',Author/ID)&$expand=Author/ID",  
        method: "GET",                                                                  // ?$select=Title,PeopleField/ID&$filter=substringof('"+currentUserId+"',PeopleField/ID)&$expand=PeopleField/ID";
        headers: {  
            "accept": "application/json;odata=verbose",  
            "content-type": "application/json;odata=verbose"    
        success: function(data) {  
            data = data.d.results;
            $.each(data, function(index, value) {  

    var html = "<tr><td>"+"<a href='#' onclick='View1(" + value.Id + ")' data-target='#viewreport' data-toggle='modal'>"+value.Title+
            "</td>+<td>"+"<a href='#' class='edit' onclick='Edit("+ value.Id +")' data-target='#editEmployeeModal' data-toggle='modal'><i class='material-icons' data-toggle='tooltip' title='Edit'>&#xE254;</i></a>" +
            "<a href='#' class='delete' onclick='Delete(" + value.Id + ")' ><i class='material-icons' data-toggle='tooltip' title='Delete'>&#xE872;</i></a>"+


        error: function(error) {  
  • 1
    try it as value.Title0 ? value.Title0 : "" and check. You need to do it for other fields as well ! Sep 17, 2018 at 6:21

1 Answer 1


You can use it as value.Department ? value.Department : "" which is a JS ternary operator.

Basically it acts like an if condition as below:

    value.Department = value.Department;
    value.Department = "";

You need to do this for other fields as well to check for undefined or null values and convert them to empty string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.