cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Workflow Hero

How to automatically look up another list when a form opens

Hi,

 

We’re moving from an on-premise SP2010 and InfoPath forms environment to using SP365 with Nintex Forms, but I’m struggling to do certain things in Nintex that I can easily do in InfoPath.

 

I often use Data Connections in InfoPath to get items from others lists on the SP site and I use that information to control what gets displayed on the form.  For example, on Form Load I query the current username against a different list and if there is a row in that list for the user, then it displays/hides sections on the form and displays a value from a different column on the list that was looked up.

 

With Nintex, I’m presuming I need to use JavaScript to do this list lookup in the forms 'Custom JavaScript' section, using the  NWF$('document').ready(function() function.  Does that sound right?

 

I’m struggling to work out how to do the lookup though – can anyone give me a point in the right direction please?

 

Many thanks,

Labels: (2)
Tags (1)
0 Kudos
Reply
4 Replies
Workflow Hero

Re: How to automatically look up another list when a form opens

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How to automatically look up another list when a form opens

Thanks for that - just what I was after I think.  Not sure how I missed finding that when I searched the support pages

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How to automatically look up another list when a form opens

Hello, I think my last post can help you to do this.

To sum up, I get value from a list in another Sharepoint Site with custom JS. I put on my post the full code so if it correspond, enjoy =) If you have question, contact me

Problem to get value into javascript variable ?

Hope I can be usefull

Bye

Theo

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How to automatically look up another list when a form opens

I think I've finally sussed this - posting this here in case anyone else finds it useful.

First, just to confirm what I was trying to do:

I have a list called "Financial Periods" which has columns called "Date", "Financial Week" and "Financial Period" in it, populated with data:

Capture.JPG

I have another list and on it's form are fields for "Financial Week" and "Financial Period".  When a new item is created, I want to look up the current date in the "Financial Periods" list and automatically populate the corresponding "Financial Week" and "Financial Period" fields on this form.

This is the entire JavaScript I have in my Forms Custom JavaScript field:

NWF.FormFiller.Events.RegisterAfterReady(function (){
  var currentdate = new Date();
  var today = currentdate.getFullYear() + '-' + (currentdate.getMonth() + 1) + '-' + ("0" + (currentdate.getDate())).slice(-2) + ' 00:00:00Z';
 
  var web = clientContext.get_web();
  var oList = web.get_lists().getByTitle("Financial Periods");
  var camlQuery = new SP.CamlQuery();

  camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Date\' /><Value Type=\'DateTime\' IncludeTimeValue=\'FALSE\'>' + today + '</Value></Eq></Where></Query></View>');

  this.collListItem = oList.getItems(camlQuery);
  clientContext.load(collListItem);
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
});

function onQuerySucceeded(sender, args) {
  var varFinancialPeriod;
  var fldFinancialPeriod = NWF$("#" + FinancialPeriod);
  var varFinancialWeek;
  var fldFinancialWeek = NWF$("#" + FinancialWeek);
 
  var listItemEnumerator = collListItem.getEnumerator();
  while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
varFinancialPeriod = oListItem.get_item('Financial_x0020_Period');
varFinancialWeek = oListItem.get_item('Financial_x0020_Week');
  }
  fldFinancialPeriod.val(varFinancialPeriod);
  fldFinancialWeek.val(varFinancialWeek);
}

function onQueryFailed(sender, args) {
  alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

0 Kudos
Accept as Solution Reply