Page 1 of 1

Pass 2 distinct values to new /edit form

Posted: 19 Feb 2018
by mustangdjb
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();

Re: Pass 2 distinct values to new /edit form

Posted: 20 Feb 2018
by Nikita Kurguzov
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.