PreFill Form Field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
bburke
Posts: 24
Joined: Fri May 24, 2013

26 May 2013

I have two lists, "Pipeline" and "Notes". I am following the blog post http://spform.com/forms-designer- ... ist-part-2

I want to prefill the "Pipeline" field in the New Item Notes form with the "Title" field from the "Pipeline" form.

In the Parent (Pipeline) Edit form I enter the following in the js-editor:

Code: Select all

// getting query string hash
var queryString = SP.ScriptHelpers.getDocumentQueryPairs();
// adding get-parameter 'order' into new item link
newItem.attr('onclick', 
  'NewItem2(event, "' + newItem.attr('href') + '&Title=' + queryString['ID'] + '"); return false;')
In the (Notes) New Item Form, I enter the following in the js-editor:

Code: Select all

// getting query string hash
var queryString = SP.ScriptHelpers.getDocumentQueryPairs();
// fill order number
fd.field('Pipeline').control().value(queryString['Title']);
I see the Title ID in the url when I open the Notes NewItem Form.

But the Title ID in the url is populating the "Title" field in the Notes New Item Form.

Am I doing something wrong?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

27 May 2013

Thanks for your great support helping me solve my issue.

bburke
Posts: 24
Joined: Fri May 24, 2013

27 May 2013

First, you have to rename your get-parameter. SharePoint prefills Title field with parameter named ‘Title’.

How many items are in Pipeline list?

This script works only if items count in the dropdown is less than 20:

Code: Select all

fd.field('Pipeline').control().value(queryString['Title']);
Use this one, that works for any count of related items:

Code: Select all

var queryString = SP.ScriptHelpers.getDocumentQueryPairs(); 
var id = queryString['Title'];

if (fd.field('Parent').control()._el().find('input').length > 0) {
  var control = fd.field('Parent').control()._el().find('input');
  var options = control.attr('choices').split('|');
  $.each(options, function(i) {
    if (i % 2 == 1 && parseInt(this) == id) {
      $('#' + control.attr('optHid')).val(id);
      control.val(options[i-1]);
      return false;
    }
  })
} else {
  fd.field('Parent').control().value(id);
}
My lookup field called ‘Parent’, so, you have to rename it to ‘Pipeline’.

bburke
Posts: 24
Joined: Fri May 24, 2013

30 May 2013

This works in Internet Explorer but is not working in Firefox 21.0. Can you assist?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

31 May 2013

I have just checked this code in the latest version of FF and it seems it works correctly. Please, verify that you have correct internalName in the highlighted line:

Code: Select all

if (fd.field('Parent').control()._el().find('input').length > 0) {
  var control = fd.field('Parent').control()._el().find('input');
  var options = control.attr('choices').split('|');
  $.each(options, function(i) {
    if (i % 2 == 1 && parseInt(this) == id) {
      $('#' + control.attr('optHid')).val(id);
      control.val(options[i-1]);
      return false;
    }
  })
} else {
  fd.field('Parent').control().value(id);
}

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests