PreFill Form Field
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:
In the (Notes) New Item Form, I enter the following in the js-editor:
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?
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;')
Code: Select all
// getting query string hash
var queryString = SP.ScriptHelpers.getDocumentQueryPairs();
// fill order number
fd.field('Pipeline').control().value(queryString['Title']);
But the Title ID in the url is populating the "Title" field in the Notes New Item Form.
Am I doing something wrong?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Thanks for your great support helping me solve my issue.
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:
Use this one, that works for any count of related items:
My lookup field called ‘Parent’, so, you have to rename it to ‘Pipeline’.
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']);
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);
}
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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);
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 24 guests