Pass 2 distinct values to new /edit form

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
mustangdjb
Posts: 4
Joined: Tue Jan 30, 2018

19 Feb 2018

Hello, I am just learning Javascript and have been relying heavily on copy/paste as I figure things out (so bear with me)

I have a situation where I need to pass 2 values from a related list to the Edit/ new functions.

I am able to pass the ID (to create new values and link the related items) but I am struggling to pass the second Value (association).

on the parent form I have this: (the ContractorEquipment id is the ID, and Assocation is the second value)

fd.populateFieldsInGrid($('.related-assoc'), {
Association: '{CurrentItem}',
});
fd.populateFieldsInGrid($('.related-items'), {
ContractorEquipmentID: '{CurrentItem}',

in the receiving form I have this (New)- this populates the value then hide/shows specific fields based on the association.

if (window != window.top && window.top.fd) {
// the form is opened in a dialog from the parent form
var parentId = window.top.GetUrlKeyValue('ID');
var AssocId = window.top.GetUrlKeyValue('Association_x0020_Name');

if (parentId) {
// the form is opened from the Edit form
fd.field('ContractorEquipmentID').value(parentId);
fd.field('Association').value(parentid);
} else {
// the form is opened from the New form
$('#_fd_parent_temp > input').val(window.top.fd._tempParentId());
fd.field('Association').value(AssocId);
}

$('.related-equipment').hide();
}

function HideShow() {
if (fd.field('Association').value() == 'TOMA') {
// Setting the Percent Complete to 100
$('.ded-wmca').hide();

// Getting JQuery-object of the field container and hide it

} else {
// Getting JQuery-object of the field container and show it
$('.ded-toma').hide();

}
}

HideShow();

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

20 Feb 2018

Dear mustangdjb,
In general, it's fairly easy to pass an existing field value from parent to child item, you can add code like this to the child's New Form:

Code: Select all

if (window != window.top && window.top.fd) {
  // the form is opened in a dialog from the parent form

  //grab the value first:
  var assoc = window.top.fd.field('Association_x0020_Name').value();
  //insert it into field:
  fd.field('Association').value(assoc);

  //the rest of the code...
  var parentId = parseInt(window.top.GetUrlKeyValue('ID'));
  if (parentId) {
    // the form is opened from the Edit form
    fd.field('Parent').value(parentId);
  } else {
    // the form is opened from the New form
    $('#_fd_parent_temp > input').val(window.top.fd._tempParentId());
  }
   
  $('.parent-field').hide();
}
You don't need to use populateFieldsInGrid on parent here, and you also don't need to use GetUrlKeyValue, as it is not an ID, it's a field. Tell me if you have any other questions, but this should work.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests