Set Editable Default Values for New Row

  • 1
  • Question
  • Updated 3 months ago
  • Answered
I am using a drawer to display tasks related to a custom object.  My drawer contains a table, and I'm using Context conditions on the table to display the appropriate tasks.  (WhatId of Records = Id of row in context.)  When I create a new row in the Tasks table, the WhatId is automatically populated with the Id of the row in context - which is exactly what I want to happen. 

I also want to populate the WhoId of my new tasks using a custom field (Contact__c) on the row in context.  The difficulty is that I want this field to be editable.  

What's the best way to set a default value in a new row in a drawer, and allow it to be editable?  If it's a snippet, how do I get the Id of the row in context?
Photo of Elissa Bradley

Elissa Bradley

  • 1,672 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
If you're running the create row as a row action I believe that the row in context gets passed into the snippet. Try putting a
console.log(arguments);
in the beginning of your snippet and see what you get. I think it'g going to be something like this:
var params = arguments[0],
    model = params.model,
    item = params.item,
    row = item.row;
console.log(row); // should be the row you want
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
While Moshe was thinking in code,  I was thinking declaratively.  But ran into a problem. 

If you are using the following method to pass the contactID into the Who ID,  you should be able to subsequently edit the value. 
- On your Task model add a condition on WhoId that is filterable default off. 
- Add a second condition on Who.Name that is filterable default off. 
- In your "Before Load Actions" on the drawer have a sequnece as follows:
      - Activate the WhoId  condition and give it the value of the contact_c from the row in context. 
      - Activate the Who.Name condition and give it the value of the contact__r.Name field from the row in context. 
      - Query the Task model (but Merges in new Rows into the existing set)

Now we run into a problem.  When you add a new task inside the drawer, and go to edit the WhoId - we throw a javascript error because the WhoId is a polymorphic field.  We are working to fix this bug,  but I think you can get around the issue if you force the WhoId always to refer to a Contact record.  Here is a post describing how to do that.  
Photo of Elissa Bradley

Elissa Bradley

  • 1,672 Points 1k badge 2x thumb
Thanks to both of you!  

Rob, I did what you said and it works perfectly.  I already had a custom snippet running on the contact to define WhoId, so - no errors.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Sweet!!!
Photo of Ambrose Alward

Ambrose Alward

  • 300 Points 250 badge 2x thumb
Thank you both!!!   Saved me a ton of time!