You need to sign in to do that
Don't have an account?
Hyperlink Formula - execute javascript? - one click Task Completed button
Can I create a hyperlink formula field that will execute javascript? I have a custom detail page button on tasks that marks a task complete with the following code:
{!requireScript("/soap/ajax/10.0/connection.js")};
sforce.connection.session = "{!$Api.Session_ID}";
function updateTask( )
{
try
{
var task = new sforce.SObject("Task");
task.Id = "{!Task.Id}";
task.Status = "Completed";
var result = sforce.connection.update([task]);
if (result[0].getBoolean("success") == false ) {
alert(result[0].errors.message);
return;
}
window.top.location.href=window.top.location.href;
}
catch (e) {
alert(e);
}
}
updateTask();
I'm trying to show this function in a list view. I couldn't get a list button to work with this code so I was hoping if I could create a formula field to display a link that would do the same thing as the button, I could just add the field to my related list.
I'm trying to give my users the ability to mark tasks complete in a list view with one click (similar to home page functionality, but on opportunties).
Has anyone done this before? Is it even possible?
Did you ever figure this out? Trying to do the same thing, but no way I can see to do it...
Hi Brandit,
The problem in your code is that you are handling single record to update, since in case of ListButton you are gonna place this button to task related list. So it will be expecting multiple records (which have user selected from list view).
Try the following code -
{!requireScript("/soap/ajax/10.0/connection.js")};
sforce.connection.session = "{!$Api.Session_ID}";
function updateTask( )
{
try
{
var records = {!GETRECORDIDS($ObjectType.Task)};
var allrecords=new Array();
if (records[0] == null) {
alert("Please select at least one record.")
}
else{
for(var i=0;i<records.length;i++)
{
var task = new sforce.SObject("Task");
task.Id = records[i];
task.Status = "Completed";
allrecords.push(task);
}
var result = sforce.connection.update(allrecords);
for(var j=0;j<result.length;j++){
if (result[j].getBoolean("success") == false ) {
alert(result[j].errors.message);
return;
}
}
window.top.location.href=window.top.location.href;
}
}
catch (e) {
alert(e);
}
}
updateTask();
Hopw it will work !!
https://sfdc-gyaan.rhcloud.com/2014/04/referencing-javascript-file-from-static-resources-in-formula-fields/
Hope this helps!
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var ProcTask = new sforce.SObject("FSTR__Process_Task__c");
ProcTask.Id = '{!FSTR__Process_Task__c.Id}';
ProcTask.FSTR__Status__c = 'Completed';
var result = sforce.connection.update([ProcTask]);
location.reload(true);