Can I change this code for use with a custom object?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
This code is for marking Tasks as complete. I don't know much JS. I want to replace the standard object Tasks with a custom object. I thought I would only have to change the Status, Complete and then make sure the model was correct. 

Any advice?
skuid.snippet.registerSnippet('tasks.markCompleted',function(params){
   console.log('test');
   // Mark all selected items as closed,
   // then save our 2 Tasks models
   var model = params.model,
       list = params.list,
       selectedItems = params.item ? [params.item] : list.getSelectedItems();
   if (selectedItems.length === 1 && skuid.model.isNewId(selectedItems[0].row.Id)) {
       alert('Please finish creating this Task before marking it as completed.');
       return;
   }
   $j.each(selectedItems,function(i,item){
       model.updateRow(item.row,'Status','Completed');
   });
   // Block the list from having updates
   list.element.block({
       css: list.blockUICSS, overlayCSS: list.blockOverlayCSS,
       message:'Marking Tasks as Completed...'
   });
   var saveFinishes = model.save({callback:
       function(){
           var updateFinishes = skuid.model.updateData([model,skuid.model.getModel('TaskHistory')]);
           $j.when(updateFinishes).then(
               function(){ list.element.unblock(); },
               function(){ list.element.unblock(); }
           );
       }
   }); 
});
Photo of Sara M

Sara M

  • 90 Points 75 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Sara M,

This snippet is setup to mark selected tasks in a table completed.  If your goal is to mark selected rows (any object) as 'completed', I would recommend that you setup a Mass Action on the table.  You can use Skuid action steps to update any fields and save the changes for each record that was selected.

Thanks,

Bill