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
Mary Ardelyn NabongMary Ardelyn Nabong 

How to get Standard fields using custom button and Javascript

Hi,

On the Order object I have a requirement to create custom button to check if the custom field(check box) in object Account object is check or not. Can I do this using Javascript only if yes, can anybody show me? if no  and i need to do a VF and controller on this please let me know

Example of displaying custom field in an order:
alert('{!Order.SAP_Status__c}');

but if i want to display using the standard fields like Accountname, accountNumber, how will get these value.


Thanks,
Smurfet

 
 
Best Answer chosen by Mary Ardelyn Nabong
Swayam  AroraSwayam Arora
Yes, it can be done custom button using a trick. Below is a simple example:-

Step1 : Create a checkbox field in Account. In my case it is 'IsActive__c'
Step2 : Create one formula field in Order named 'IsAccountActive__c' with formula 'Account.IsActive__c'
Step3 : Create one Custom Button with below code
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var isActive = '{!Order.IsAccountActive__c}';

if(isActive == 1) {
alert('Account is active');
} else {
alert('Account is inactive');
}

Let me know if you need further help.

Please close the thread marking this answer as Best Answer if it really helped. Closing the thread help others finding the correct answer.

All Answers

Swayam  AroraSwayam Arora
Yes, it can be done custom button using a trick. Below is a simple example:-

Step1 : Create a checkbox field in Account. In my case it is 'IsActive__c'
Step2 : Create one formula field in Order named 'IsAccountActive__c' with formula 'Account.IsActive__c'
Step3 : Create one Custom Button with below code
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var isActive = '{!Order.IsAccountActive__c}';

if(isActive == 1) {
alert('Account is active');
} else {
alert('Account is inactive');
}

Let me know if you need further help.

Please close the thread marking this answer as Best Answer if it really helped. Closing the thread help others finding the correct answer.
This was selected as the best answer
Jason Reiber [ACS]Jason Reiber [ACS]
I'm not sure I entirely understand your requirement.  Why not just create a formula field on the Order object to return the value of the checkbox on the Account instead of creating a button to do that?

Either way though, I don't understand what the challenge is with accessing the standard fields, can't you just use something like Order.Account.Whatever?  Also, both Account Name and Account Number are fields that are already on the Order object so no cross-object formula is needed for those.
Mary Ardelyn NabongMary Ardelyn Nabong
Hi Swayam,
It works and thank you.   how to close the thread.

Jason, 
I can see on the UI that Account Name and Account Number are there in the Order standard fields but when I do my SOQL I cannot see this Account No and Account Name but I see Account ID. Can you please help me how to access in the SOQL?

I am new here so thanks for bearing with me.

Thanks,
Smurfet


 
Mary Ardelyn NabongMary Ardelyn Nabong
Hi Swayam,
My program works fine with or without this:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

May  I know what is the relevance of this?  My worry is what is going to happen if the version changes to much higher, is there going to be an impact on my program.


Thanks,
Mary 
Swayam  AroraSwayam Arora
These are javascript files used to make ajax calls and make calls to Apex Code. You can checkout below link.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm