function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter Russell 9Peter Russell 9 

Custom button to clear field data

Hi,

I would like to create a jscript button to clear two fields in an opportunity when pressed.
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Task_Due__c = " ";
c.Task_Notes__c = " ";
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

Above is the code I am trying but I just get error messages. The Task_Due and Task_Notes are the custom fields I am trying to reset to empty. Task Due is a date field and Task Notes is a long text field.

Anyone have any ideas on what is wrong or what needs correcting?

Thanks,
Pete 
Saravana Muthu 8Saravana Muthu 8
Hi,

Please use the below code in the button.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Task_Due__c = null;
c.Task_Notes__c = " ";
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

Thanks,
Sarav
Sweet Potato tec
Peter Russell 9Peter Russell 9
That's great thank you.

Just that null that was missing!
Saravana Muthu 8Saravana Muthu 8
Hi,

Please mark it as best answer if it's resolved.

So that it will be helpful to others.

Thanks,
Sarav
Sweet Potato Tec
Peter Russell 9Peter Russell 9
Hi,

Just to follow up - the button is working great. 

Just wondeting if there is a way for SF to take the data that is in the fields (Date/time & Text) and either input it into a post on the opportunity page or create a completed task with that info.

Just to give context, the fields are a method of setting tasks, once the task is complete, the button will clear the fields but I would like a trail of what was input into the fields.

Thanks,
Pete 
Saravana Muthu 8Saravana Muthu 8
Hi,

Yes, you can create a proces builder to achieve this.

Step 1 : Select 'Opportunity' as object with 2nd condition.

User-added image

Step 2: Create the criteria as ISCHANGED([Opportunity].Task_Due_Date__c)  && ISBLANK([Opportunity].Task_Due_Date__c) 
&& ISCHANGED([Opportunity].Task_Notes__c)  && ISBLANK([Opportunity].Task_Notes__c) 


User-added image

Step 3: Immediate Action with Task object and fill the mandatory fields.To get the Task_Due_Date__c and Task_Notes__c in Task object use the PRIORVALUE fuction and use the related to ID field to relate the task to Opportuity.

User-added image

Please let me know if you can able to follow the steps.

Thanks,
Sarav
Sweet Potato Tec
 
Peter Russell 9Peter Russell 9
Hi Sarav,

Yes I can follow these steps, I am a complete novice when it comes to coding so I have no idea what formulae are supposed to go in the field in Step 3, could you please let me know?

Thanks,
Pete 
Peter Russell 9Peter Russell 9
No worries - I have figured it out, works flawlessly. 

Thank you for your help. 
Saravana Muthu 8Saravana Muthu 8
Hi,

In step 3 if you select Due Date and Select Formula as the value and paste the below line.

PRIORVALUE([Opportunity].Task_Due_Date__c ) 

User-added image


Paste the beow line for Subject  and Select Formula as the value and paste the below line.

PRIORVALUE([Opportunity].Task_Notes__c ) 

User-added image

Please let me know if you can't follow the steps.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

Thanks,
Sarav
Sweet Potato Tec

 
Peter Russell 9Peter Russell 9
Hi Sarav, just one issue - it is not completing the due date field. Could it be because I am using a date/time field? If so, do you know if there is a way around this.

Thanks
Saravana Muthu 8Saravana Muthu 8
Hi,

You could using PRIORVALUE(DATEVALUE([Opportunity].Task_Due_Date__c ) )

If your field is date and time and you need to get only date.

Thanks,
Sarav
Sweet Potato Tec
 
Peter Russell 9Peter Russell 9
Hi, 

I get the following error:

The formula expression is invalid: Incorrect argument type for function 'PRIORVALUE()'.

Thanks,
Pete
Saravana Muthu 8Saravana Muthu 8
Sorry, it should be like below.

DATEVALUE(PRIORVALUE([Opportunity].Due_Date_Time__c )  ) 

Thanks,
Sarav
Sweet Potato Tec
Saravana Muthu 8Saravana Muthu 8
Hi,

Please mark this thread as solved if it was helped.

So that others will be able to get help from this.

Thanks,
Sarav
Sweet Potato Tec
Catherine CruzCatherine Cruz
I'm also trying to create a button to clear some fields from a custom object. Can anyone help me out?

The fields are populated to be able to show a what-if scenario if additional costs were to hit our project. I'd like to have the ability to set them back to $0 once the user has checked the addition costs or deductions. This is on a custom object 'Proj Sales Distribution' ID a1c4u000003WfVHAA0

User-added image
  • Material_Add_On__c
  • Labor_Add_On__c
  • Misc_Add_On__c
  • Order_Increases_By__c