I am trying to allow mass completion of tasks and the creation of a follow-up tasks for each lead/contact in a single popup.
Desired behaviour:
- User selects tasks for mass-completion and follow-up
- User hits mass action button
- Pop-up appears allowing user to update a field on the existing task and also create a new task for each selected record
- Pop-up works to auto-mass-complete existing tasks and display the fields I want for new task creation
Where I’m stuck:
I just can’t seem to manage the new task creation and context correctly. Either I’m able to create a new task, but I get a list of all contacts/leads instead of only those I want to create a new task for, or else I only seem to display existing tasks for those leads.
The code I’m using is below. I have a suspicion I need to either be using the context argument when calling my popup or else model.createRow, but it’d be great to get some guidance either way.
Thanks!
var $ = skuid.$,action = arguments 0].action,
list = arguments 0].list,
$xml = skuid.utils.makeXMLDoc,
model = arguments 0].model;
var NewTaskModel = skuid.model.getModel('NewTask');
var TasksModel = skuid.model.getModel('Tasks');
var selectedItems = list.getSelectedItems();
var rowsToUpdate = {};
var selectedTasks = e];
var listOfInfo = t];
arrayOfTaskInfo = a];
listOfWhoIds = f];
$.each( selectedItems,
function( i, item )
{
var row = item.row;
rowsToUpdatew row.Id ] = { Status: 'Completed' };
selectedTasks.push(row.Id);
listOfInfo.push("<value>" + row.Id + "</value>");
listOfWhoIds.push(row.WhoId);
arrayOfTaskInfo.push({
WhoId: row.WhoId,
OwnerId: row.OwnerId,
Type: "To-Do",
Status: "Not Started",
Subject: "",
ToDoDate: "",
Notes: ""
});
});
listOfInfo = listOfInfo.join('');
listOfWhoIds = listOfWhoIds.join('');
console.log(arrayOfTaskInfo);
model.updateRows(rowsToUpdate);
var popupXMLString = '<popup width="90%" title="Create follow-ups">'
popupXMLString += '<components>'
popupXMLString += '<pagetitle model="Tasks">'
popupXMLString += '<maintitle>Create follow-ups</maintitle>'
popupXMLString += '<actions>'
popupXMLString += '<action type="custom" snippet="" label="Save and create follow-ups" icon="ui-silk-accept"/>'
popupXMLString += '</actions>'
popupXMLString +='</pagetitle>'
popupXMLString += '<panelset type="standard" uniqueid="sk-3AZ3Uv-475" scroll="">'
popupXMLString += '<panels>'
popupXMLString += '<panel type="left" width="300px">'
popupXMLString += '<components>'
popupXMLString += '<basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="Tasks" buttonposition="" uniqueid="sk-3AZDsA-519" mode="read">'
popupXMLString += '<columns>'
popupXMLString += '<column width="100%">'
popupXMLString += '<sections>'
popupXMLString += '<section title="{{Subject}} - {{WhoId}}">'
popupXMLString += '<fields>'
popupXMLString += '<field id="Description" required="false"/>'
popupXMLString += '</fields>'
popupXMLString += '<renderconditions logictype="and">'
popupXMLString += '<rendercondition type="multiple" operator="in" fieldmodel="Tasks" sourcetype="fieldvalue" nosourcerowbehavior="skipandnorender" field="Id" value="" enclosevalueinquotes="false">'
popupXMLString += '<values>'
popupXMLString += listOfInfo
popupXMLString += '</values>'
popupXMLString += '</rendercondition>'
popupXMLString += '</renderconditions>'
popupXMLString += '</section>'
popupXMLString += '</sections>'
popupXMLString += '</column>'
popupXMLString += '</columns>'
popupXMLString += '</basicfieldeditor>'
popupXMLString += '</components>'
popupXMLString += '</panel>'
popupXMLString += '<panel>'
popupXMLString += '<components>'
popupXMLString += '<basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="Tasks" buttonposition="" uniqueid="sk-3AZF96-543" mode="read">'
popupXMLString += '<columns>'
popupXMLString += '<column width="50%">'
popupXMLString += '<sections>'
popupXMLString += '<section>'
popupXMLString += '<fields>'
popupXMLString += '<field id="WhoId" required="false"/>'
popupXMLString += '</fields>'
popupXMLString += '<renderconditions logictype="and">'
popupXMLString += '<rendercondition type="multiple" operator="in" fieldmodel="Tasks" sourcetype="fieldvalue" nosourcerowbehavior="skipandnorender" field="Id" value="" enclosevalueinquotes="false">'
popupXMLString += '<values>'
popupXMLString += listOfInfo
popupXMLString += '</values>'
popupXMLString += '</rendercondition>'
popupXMLString += '</renderconditions>'
popupXMLString += '</section>'
popupXMLString += '</sections>'
popupXMLString += '</column>'
popupXMLString += '<column width="50%">'
popupXMLString += '<sections>'
popupXMLString += '<section>'
popupXMLString += '<fields>'
popupXMLString += '<field id="Status" required="false" value="Not Started"/>'
popupXMLString += '<field id="Type" required="false" value="To-Do"/>'
popupXMLString += '</fields>'
popupXMLString += '<renderconditions logictype="and">'
popupXMLString += '<rendercondition type="multiple" operator="in" fieldmodel="Tasks" sourcetype="fieldvalue" nosourcerowbehavior="skipandnorender" field="Id" value="" enclosevalueinquotes="false">'
popupXMLString += '<values>'
popupXMLString += listOfInfo
popupXMLString += '</values>'
popupXMLString += '</rendercondition>'
popupXMLString += '</renderconditions>'
popupXMLString += '</section>'
popupXMLString += '</sections>'
popupXMLString += '</column>'
popupXMLString += '</columns>'
popupXMLString += '</basicfieldeditor>'
popupXMLString += '</components>'
popupXMLString += '</panel>'
popupXMLString += '</panels>'
popupXMLString += '</panelset>'
popupXMLString += '</components>'
popupXMLString += '</popup>';
var popupXML = $xml(popupXMLString);
// Launch the popup
var popup = skuid.utils.createPopupFromPopupXML(popupXML);
console.log(listOfWhoIds);