Row action to log task under assigned account name

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I am having troubles creating a row action on an account table which will render a popup with the WhoId already populated to that row's account.. This seems like it would be simple, but I try to set the context and then the field editor does not render.
Photo of Jake Stallman

Jake Stallman

  • 386 Points 250 badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Have you set the condition of the model of the table in popup to be whoid to be equal to the account id?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Sorry, the condition of the model of the field editor in popup to be whoid to be equal to the account id?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Also to note. The Account Name doesn't seem to show until the task has been saved. I think that's because the WhatId is used behind the scenes to update this field after saving the record. Actually, it must be done this since the task table is dynamically attached to any object in the system. There would be no way to display the Account Name until after saving the record.
Photo of Jake Stallman

Jake Stallman

  • 386 Points 250 badge 2x thumb
Bummer, so there is no way to have the Whatid field render based on the account row in context?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Close. I included the whatid in the popup and got this.

Photo of Jake Stallman

Jake Stallman

  • 386 Points 250 badge 2x thumb
That looks right! How did you do that? 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true" tabtooverride="Account">   <models>
      <model id="Account" limit="100" query="true" createrowifnonefound="false" sobject="Account">
         <fields>
            <field id="Name"/>
            <field id="CreatedDate"/>
         </fields>
         <conditions/>
         <actions/>
      </model>
      <model id="NewTask" limit="" query="false" createrowifnonefound="true" sobject="Task" doclone="" type="">
         <fields>
            <field id="AccountId"/>
            <field id="Account.Name"/>
            <field id="WhatId"/>
            <field id="What.Name"/>
            <field id="Subject"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="WhatId" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <pagetitle model="Account">
         <maintitle>
            <template>{{Model.labelPlural}}</template>
         </maintitle>
         <subtitle>
            <template>Home</template>
         </subtitle>
         <actions/>
      </pagetitle>
      <skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Account" mode="read">
         <fields>
            <field id="Name" allowordering="true"/>
            <field id="CreatedDate" allowordering="true"/>
         </fields>
         <rowactions>
            <action type="edit">
               <drawer title="Drawer Area" width="800" closehandle="true">
                  <components/>
               </drawer>
            </action>
            <action type="delete"/>
            <action type="popup" label="Account Tasks" icon="sk-icon-activities">
               <drawer title="Drawer Area" width="800" closehandle="true">
                  <components/>
               </drawer>
               <popup width="80%" title="Viewing {{Model.label}}: {{Name}}">
                  <components>
                     <basicfieldeditor showheader="true" showsavecancel="true" mode="edit" model="NewTask" buttonposition="" layout="">
                        <conditions>
                           <condition type="contextrow" field="WhatId" mergefield="Id" autocreated="true"/>
                        </conditions>
                        <columns>
                           <column width="100%">
                              <sections>
                                 <section title="Task Info" collapsible="no">
                                    <fields>
                                       <field id="Subject"/>
                                       <field id="WhatId" valuehalign="" type="" readonly="true"/>
                                    </fields>
                                 </section>
                              </sections>
                           </column>
                        </columns>
                     </basicfieldeditor>
                  </components>
               </popup>
               <actions>
                  <action type="createRow" model="NewTask" appendorprepend="prepend" defaultmodefornewitems="read">
                     <defaults>
                        <default type="fieldvalue" field="WhatId" enclosevalueinquotes="true" value="{{Id}}"/>
                     </defaults>
                  </action>
                  <action type="save" rollbackonanyerror="true">
                     <models>
                        <model>Task</model>
                     </models>
                     <onerroractions>
                        <action type="blockUI" message="There was an error" timeout="3000"/>
                     </onerroractions>
                  </action>
                  <action type="showPopup">
                     <popup title="New Popup" width="800">
                        <components>
                           <pagetitle model="NewTask">
                              <maintitle>
                                 <template>{{Subject}}</template>
                              </maintitle>
                              <subtitle>
                                 <template>{{Model.label}}</template>
                              </subtitle>
                              <actions>
                                 <action type="save" label="Save" window="self" rollbackonanyerror="true"/>
                                 <action type="multi" label="Cancel" window="self">
                                    <actions>
                                       <action type="markRowsForDeletion" model="Account"/>
                                       <action type="save" rollbackonanyerror="true">
                                          <models>
                                             <model>NewTask</model>
                                          </models>
                                          <onerroractions>
                                             <action type="blockUI" message="There was an error" timeout="3000"/>
                                          </onerroractions>
                                       </action>
                                       <action type="closeTopmostPopup"/>
                                    </actions>
                                 </action>
                              </actions>
                           </pagetitle>
                           <basicfieldeditor showheader="true" showsavecancel="false" model="NewTask" buttonposition="" mode="edit" layout="">
                              <columns>
                                 <column width="100%">
                                    <sections>
                                       <section title="Section A" collapsible="no">
                                          <fields>
                                             <field id="Subject" valuehalign="" type=""/>
                                             <field id="Account.Name"/>
                                          </fields>
                                       </section>
                                    </sections>
                                 </column>
                              </columns>
                           </basicfieldeditor>
                        </components>
                     </popup>
                  </action>
               </actions>
            </action>
         </rowactions>
         <massactions usefirstitemasdefault="true">
            <action type="massupdate"/>
            <action type="massdelete"/>
         </massactions>
         <views>
            <view type="standard"/>
         </views>
      </skootable>
   </components>
   <resources>
      <labels/>
      <css/>
      <javascript/>
   </resources>
</skuidpage>
Photo of Jake Stallman

Jake Stallman

  • 386 Points 250 badge 2x thumb
I got it! Just in case anyone ever searches this, I used this snippet to create a new task who's account is assigned as the row in context. I needed this row action to render a popup so I could log tasks to that account without having to actually go in the account.

var params = arguments[0],
    accountRow = params.item ? params.item.row : params.row,
    accountModel = params.model,
$ = skuid.$;
// Create our new Task
var NewTaskModel = skuid.model.getModel('LogAction');
var NewTask = NewTaskModel.createRow();
NewTaskModel.updateRow(NewTask,{
   'WhatId': accountRow.Id
});
// Link our Account to this Task
accountModel.updateRow(accountRow,{
    'WhatId':NewTask.Id,
    'Task':NewTask
});
// Return our new Task row as our context
return {
    row: NewTask    
};