Page 1 of 1

Display Username in CSL

Posted: 28 Nov 2016
by Mostafa Mohamed
i need to display the user display name in csl field via an "Assigned To" column, but curruntly displaying "undifined", here my code and screen shot:

Request items:

function (term, page) {

if (!term || term.length == 0) {

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Title,ActivationDate&$orderby=Created desc&$top=10";

}

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Title,ActivationDate&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";

}



Item format:


function(item) {

return '<div style="height: 50px; clear: both;"><div style="width: 45px; float: left;"></div><span>' + item["Title"] + "<br>" + item["{LookupField}"] + "<br>" + item["ActivationDate"] + '</span></div>';

}

Re: Display Username in CSL

Posted: 28 Nov 2016
by Dmitry Kozlov
Hi,

Please, try these snippets:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id," +
    "{LookupField},User/Title&$expand=User&$orderby=Created desc&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id," +
  "{LookupField},User/Title&$expand=User&$orderby={LookupField}&" + 
  "$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
Item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item["{LookupField}"] + " " + item["User"].Title + '</span>'
}