Skip to main content
Nintex Community Menu Bar

Using JavaScript to Query List

  • July 29, 2015
  • 2 replies
  • 172 views

Forum|alt.badge.img+1

I am querying a list using JavaScript, from time to time the list items are retrieved, however, there are times that it returns an access denied error.

 

103371_pastedImage_15.png

 

var web = clientContext.get_web();

var list = clientContext.get_web().get_lists().getByTitle("Employee Hours Profile");

 

var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml('<View>' +

     '<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>[ItemTitle]</Value></Eq></Where></Query>' +

          '<ViewFields>' +

               '<FieldRef Name='Title' />' +

          '</ViewFields>' +

     '<RowLimit>1</RowLimit>' +

'</View>');

 

var listItems = list.getItems(camlQuery);

 

clientContext.load(listItems);

clientContext.executeQueryAsync(onSuccess, onFail);

 

function onSuccess() {

     var listItemEnumerator = listItems.getEnumerator();

 

     while (listItemEnumerator.moveNext()) {

          var listItem = listItemEnumerator.get_current();

          var title = listItem.get_item('Title');

     }

 

     NWF$("#" + varTitle).val(title);

}

 

function onFail(sender, args) {

     alert("Error");

}

2 replies

an_old_user
Forum|alt.badge.img+4

Hi Ricardo,

The JavaScript will be executed with the permissions of the current user opening the page. 

I would check permissions on the list to ensure the users seeing this issue have access to read the list.

Thanks,

Barry.


Forum|alt.badge.img+6
  • March 4, 2016

Unfortunately, "lookup" is not existing in the runtime functions in Forms for Office 365.

It depends on the need but you can use the List lookup action in "SharePoint" category and apply a filter ('Filtering' option). May be it will necessary to use JS to get the value displayed with the action.