Getting and setting SharePoint form field values

Forms Designer provides JavaScript-framework that allows to manipulate fields in a simple JQuery manner. You can find how to set or get current field values in the official website.

But what if the field is more complex than a simple input, what if it has multiple parts of values, like lookup or date and time? How do you get lookup id and lookup text? Below I placed the table that illustrates how you get or set different value types for the most SharePoint types of fields. To create this table I used the current last version of Forms Designer: 2.7.9.

Field TypeGet / SetScript
Single Line of TextGet
fd.field('Title').value();
Set
fd.field('Title').value('Default title');
OnChange
fd.field('Title').change(function(){});
Multiline Plain Text
Field
Get
fd.field('MultipleLinePlain').value();
Set
fd.field('MultipleLinePlain')
  .value('MultipleLinePlain');
OnChange
fd.field('MultilinePlain').change(
  function(){alert('Field has been changed!')}
);
Multiline RTF FieldGet
fd.field('MultilineRichText').value();
Set
fd.field('MultilineRichText')
  .value('MultilineRichText');
OnChange
fd.field('MultilineRichText').change(
  function(){alert('Field has been changed!')}
);
Multiline Enhanced Rich Text FieldGet
fd.field('MultilineEnhanced').value();
Set
fd.field('MultilineEnhanced')
  .value('MultilineEnhanced');
OnChange
fd.field('MultilineEnhanced').change(
  function(){alert('Field has been changed!')}
);
Choice SingleGet
fd.field('ChoiceSingle').value();
Set
fd.field('ChoiceSingle').value('B');
OnChange
fd.field('Choice').change(function(){
  alert('Field changed!');
});
Choice MultipleGet
var checkboxIndex = 2;
fd.field('MultiChoice').control()._el()
  .find('input[type="checkbox"]').eq(checkboxIndex)
  .is(':checked');
Set
var checkboxIndex = 2;
fd.field('MultiChoice').control()._el()
  .find('input[type="checkbox"]').eq(checkboxIndex)
  .prop('checked', true);
OnChange
fd.field('MultiChoice').change(function(){
  alert('Field changed!');
});
NumberGet
fd.field('Number').value();
Set
fd.field('Number').value('13');
OnChange
fd.field('Number').change(function(){
  alert('Field changed!');
});
CurrencyGet
fd.field('Currency').value();
Set
fd.field('Currency').value('23');
OnChange
fd.field('Currency').change(function(){
  alert('Field changed!');
});
DateGet
fd.field('Date').value();
Get Date-object
field('Date').control('getDate') // returns Date-object
Set
fd.field('Date').value('4/21/2012'); // by String

fd.field('DateTime')
  .value(new Date()); // by Date-object
OnChange
fd.field('Date').change(function(){
  alert('Field changed!');
});
DateTimeGet
fd.field('DateTime').value()[0]; // date
fd.field('DateTime').value()[1]; // hours
fd.field('DateTime').value()[2]; // minutes
Get Date-object
field('DateTime').control('getDate') // returns Date-object
Set
fd.field('DateTime')
  .value(['4/21/2012', '11 PM', '35']); // by Array
fd.field('DateTime')
  .value(new Date()); // by Date-object
OnChange
fd.field('DateTime').change(function(){
  alert('Field changed!');
});
Hyperlink / ImageGet
fd.field('Hyperlink').value()[0]; // link
fd.field('Hyperlink').value()[1]; // descr
Set
fd.field('Hyperlink')
  .value(['http://someurl', 'description']);
OnChange
fd.field('Hyperlink').change(function() {
  alert('Changed!');
});
Single Lookup ValueGet Text
fd.field('Lookup').control('getSelectedText');
Get ID
fd.field('Lookup').value();
Set Text
fd.field('Lookup').value('Text');
Set ID
var ID = 4;
fd.field('Lookup').value(ID);
OnChange
fd.field('Lookup')
  .change(function(){});
Multi Lookup ValuesGet All
var selectedItems = fd.field('LookupMultiple')
  .control()._el().find("select:eq(1) option");
var s = '';
for (var i = 0; i < selectedItems.length; i++) {
  s += selectedItems.eq(i).text() + ';';
}
alert(s);
Get First
fd.field('MultiLookup').control()._el()
  .find("select:eq(1) option").eq(0).text()
Get Second
fd.field('MultiLookup').control()._el()
  .find("select:eq(1) option").eq(1).text()
Get ID
// first selected:
fd.field('MultiLookup').control()._el()
  .find('select:eq(1) option').eq(0).val(); 

// second selected:
fd.field('MultiLookup').control()._el()
  .find('select:eq(1) option').eq(1).val();
Set
var ID = 3;
// select element by ID:
fd.field('MultiLookup').control()._el()
  .find('select:eq(0)').val(ID); 

// add button click:
fd.field('MultiLookup').control()._el()
  .find('button:eq(0)').click();
OnChange
fd.field('MultiLookup').change(function(){
  alert('Field changed!');
});
BooleanGet
fd.field('Boolean').value();
Set
fd.field('Boolean').value('1');
OnChange
fd.field('Boolean').change(function(){
  alert('Field changed!');
});
Client People PickerGet All Logins
fd.field('User').control('ready', function() {
  var selectedUsers = fd.field('User').value();
  for (var i = 0; i < selectedUsers.length; i++) {
    alert('Login: ' + selectedUsers[i].Key);
  }
});
Set
// assign value by a display name
fd.field('User').value('Tim Watts');

// by a login
fd.field('User').value('DEV\\ann');

// or by an e-mail:
fd.field('User').value('AGibson@contoso.com');
OnChange
fd.field('User').change(function(){
  alert('Field changed!');
});
Server People Picker with multiple choiceGet All Logins
var logins = '';
$.each(fd.field('People').value()
  .dictionaryEntries,
  function() {
    logins += this.AccountName + '; ';
  });
Set
fd.field('People').value('DOMAIN\\login');
OnChange
fd.field('People').change(function(){
  alert('Field changed!');
});
Server People Picker with single choiceGet
fd.field('PersonGroupSingle')
  .value().dictionaryEntries[0].AccountName
Set
fd.field('Person').value('DOMAIN\\login');
OnChange
fd.field('Person').change(function(){
  alert('Field changed!');
});
External DataGetReturns field value of External List item:

fd.field('ExternalData').value()
  .dictionaryEntries[0]['FieldOfExternalList']

‘ExternalData’ is an internal name of the lookup column.
‘FieldNameOfExternalList’ is an internal name of the external list column.

If you include additional columns to the target list in lookup settings you will be able to get them dynamically as well:

fd.field('ExternalData').value()
  .dictionaryEntries[0]['AdditionalFieldOfExternalList']

‘AdditionalFieldOfExternalList’ is an internal name of the external list column which has been added as additional field in lookup settings.

Set
fd.field('ExternalData')
  .value({key: '__bg40003300', text: 'Item 1'});

key is BDC Identity of the selected item.
text is a display name of the selected item.

OnChange
fd.field('ExternalData').change(function(){
  alert('Field changed!');
});
Plumsail Cross-site Lookup with single valueGet ID
fd.field('CrossSiteLookup').value()
Get title
fd.field('CrossSiteLookup').control('data')['Title']
SetSet ID:

fd.field('CrossSiteLookup').value(1);

Set ID and display text:

fd.field('CrossSiteLookup')
  .value({Id: 1, Title: 'Item 1'});
OnChange
fd.field('CrossSiteLookup').change(function(){
  alert('Field changed!');
});
Plumsail Cross-site Lookup with multiple valuesGet IDsReturns an array if selected ids:

fd.field('CrossSiteLookup').value()
Get titlesFirst item:

fd.field('CrossSiteLookup').control('data')[0]['Title']

Second item:

fd.field('CrossSiteLookup').control('data')[1]['Title']
Set
fd.field('CrossSiteLookup')
  .value([{Id: 1, Title: 'Item 1'}, 
    {Id: 2, Title: 'Item 2'}])
OnChange
fd.field('CrossSiteLookup').change(function(){
  alert('Field changed!');
});
Recommend this: