locked
Access parent form attribute when creating a new record by clicking on 'new' button from the lookup screen RRS feed

  • Question

  • Scenario:

    - EntityA have a N:1 relationship to contact

    - EntityA have a N:1 relationship to entityB

    - entityB also have a N:1 relationship to contact

    1. From a contact record - entityA navigation, click new to create a new entityA record (contact lookup is pre-populated from the mapping)

    2. From entityA form, click on the entityB lookup icon to bring up the lookup dialog

    3. From the entityB lookup dialog, click "New" button to create a new entityB record

    4. On entityB form, the contact lookup is null

    I want to be able to populate the contact lookup on entityB form to be the same as the contact from entityA.

    Is there a way to do this? either:

    1. is it possible to pass in the contact id from entityA to entityB when click on "New" from the entityB lookup dialog? OR

    2. when entityB form is loaded, on the onload event, use javascript to traverse back to the original "Parent" entityA form to retrieve the contact attribute value so we can use it to populate it on the form?

    Regards,

    Joe

    Friday, January 31, 2014 6:49 AM

All replies

  • Hi Joe,

    I think your approach 2 is the way to do this, or you could possibly do this by a plugin.

    If you choose the plugin path, which is "tighter" since it doesn't require anyone using the form, you could do a plugin that triggers on update of Ent A and the lookup field to Ent B. From that plugin, fetch the record B that is referenced in the lookup, see if it has a contact reference and if not set it to the contact that Ent A is referencing.

    If you choose the JS path, you pretty much do the opposite, fetch the Ent A record that has Ent B referenced, get the contact referenced and set the same on the Ent B record. This is only run if the Ent B record doesn't have a contact in the lookup window.

    There might be a better way but I can't think of one this early in the morning :)

    Good luck!


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Friday, January 31, 2014 8:22 AM
  • Hi Richard,

    Thank you for your reply. However, the options you mentioned would not work in this scenario because the record is not saved yet, so I cannot retrieve the entityA record to get the contact reference. We are in the process of creating new records.

    Just wanted to see if anyone know how to use javascript in entityB onload event to traverse back to the original entityA form to get the contact reference, along the line of 

    window.top.opener.parent.?

    OR

    window.parent.opener.?

    Regards,

    Joe

    Monday, February 3, 2014 3:59 AM
  • Hi Joe,

    It would work if you register the plugin on create and update of ent A. You will have to create the B-record before you save the A-record hence you can do the checks I described.

    If you choose to go with a JS solution which only will work when people are using the GUI, I would do a REST call on A-records finding the one pointing to this B-record, and fetching the contact reference from that record.

    Good luck!


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Monday, February 3, 2014 10:13 AM