PreFill Form Field
Posted by bburke - May 26 ’13 at 09:45
I have two lists, "Pipeline" and "Notes". I am following the blog post http://formsdesigner.blogspot.com/2013/04/sharepoint-2013-form-with-related-items_11.html
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:
// 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:
// 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?
-
DmitryAdminMember for: 10 years 7 months 28 days
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: fd.field('Pipeline').control().value(queryString['Title']);
Use this one, that works for any count of related items:
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’.
-
bburkeMemberMember for: 9 years 8 months 14 days
Thanks for your great support helping me solve my issue.
-
bburkeMemberMember for: 9 years 8 months 14 days
This works in Internet Explorer but is not working in Firefox 21.0. Can you assist?
-
DmitryAdminMember for: 10 years 7 months 28 days
[#3]: 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:
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); }