You need to sign in to do that
Don't have an account?
sundhar.mks1.3962649227519546E12
Javascript using visualforce?
Hi
I have use the following javascript code to Custom button, How to implement the code to visualforce?
Code
==========
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var SS = sforce.connection.query("select id,Visit__c from Engineer_Checklist__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records1 = SS.getArray("records");
var RS = sforce.connection.query ("select id,Visit__c from Service_Sheet_STD__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records2 = RS.getArray("records");
var MSS = sforce.connection.query ("select id,Visit__c from Mechanical_Service_Sheet__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records3 = MSS.getArray("records");
var SW = sforce.connection.query ("select id,Visit__c from Small_Works__c where Visit__r.id='{!Visits__c.Id}' and Submit_this_Small_Works_Sheet__c=True");
var records4 = SW.getArray("records");
var PS = sforce.connection.query("select id,Visit__c from Project_Sheet__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records5 = PS.getArray("records");
if((records1.length!=0 || records2.length!=0 || records3.length!=0 || records4.length!=0 || records5.length!=0) &&
confirm("You have already submitted a sheet for this visit, are you sure you want to submit another one?")){
window.open("https://cs16.salesforce.com/a1Z/e?CF00ND0000005FbyJ={!Visits__c.Name}&CF00ND0000005FbyJ_lkid={!Visits__c.Id}&retURL={!Visits__c.Site_Contract__c}&CF00ND0000005FcIJ_lkid","_top")
}
else if(records1.length==0 && records2.length==0 && records3.length==0 && records4.length==0 && records5.length==0)
{
window.open("https://cs16.salesforce.com/a1Z/e?CF00ND0000005FbyJ={!Visits__c.Name}&CF00ND0000005FbyJ_lkid={!Visits__c.Id}&retURL={!Visits__c.Site_Contract__c}&CF00ND0000005FcIJ_lkid","_top")
}
I have use the following javascript code to Custom button, How to implement the code to visualforce?
Code
==========
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var SS = sforce.connection.query("select id,Visit__c from Engineer_Checklist__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records1 = SS.getArray("records");
var RS = sforce.connection.query ("select id,Visit__c from Service_Sheet_STD__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records2 = RS.getArray("records");
var MSS = sforce.connection.query ("select id,Visit__c from Mechanical_Service_Sheet__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records3 = MSS.getArray("records");
var SW = sforce.connection.query ("select id,Visit__c from Small_Works__c where Visit__r.id='{!Visits__c.Id}' and Submit_this_Small_Works_Sheet__c=True");
var records4 = SW.getArray("records");
var PS = sforce.connection.query("select id,Visit__c from Project_Sheet__c where Visit__r.id='{!Visits__c.Id}' and Fire_Extinguisher_Service_complete__c=True");
var records5 = PS.getArray("records");
if((records1.length!=0 || records2.length!=0 || records3.length!=0 || records4.length!=0 || records5.length!=0) &&
confirm("You have already submitted a sheet for this visit, are you sure you want to submit another one?")){
window.open("https://cs16.salesforce.com/a1Z/e?CF00ND0000005FbyJ={!Visits__c.Name}&CF00ND0000005FbyJ_lkid={!Visits__c.Id}&retURL={!Visits__c.Site_Contract__c}&CF00ND0000005FcIJ_lkid","_top")
}
else if(records1.length==0 && records2.length==0 && records3.length==0 && records4.length==0 && records5.length==0)
{
window.open("https://cs16.salesforce.com/a1Z/e?CF00ND0000005FbyJ={!Visits__c.Name}&CF00ND0000005FbyJ_lkid={!Visits__c.Id}&retURL={!Visits__c.Site_Contract__c}&CF00ND0000005FcIJ_lkid","_top")
}
Hi Mr Salesforce,
Does not check the if condition it check the else straightly, i want to add this page to formula field using HYPERLINK so i need to check the condition only in (javascript)visualforcepage , how do this?
Thanks.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello,
We are already using javascript in visualforce page, create a visualforce page which is in above message as well as create apex class.
For Hyperlink
- Go To --> Your Name --> Setup --> Create --> Objects
- Open your custom object "Visit__c"
- Click "New Button or Link"
Label - Link Label
Name - Link Name
Display Type - Detail Page Link
Behavior - Display in existing window with sidebar / Display in existing window without sidebar
Content Source - Visualforce Page
Content - Created Visualforce Page Name
Include created hyper link to the visit page layout.
Thanks,
Jigar
All Answers
Below is visualforce page and apex class code for your script.
Visualforce Page
Apex Class
Please let me know if you have any issue.
Thanks and Cheers,
Jigar
The Condition not working correctly,
NOTE: Actually (SS,RS,MSS,SW,PS) these are related list in Visit object. Every related lsit have "submited sheet" field this field is checkbox. any one of the Related list have submited sheet in visit object the Warning should be display oetherwise the record should create normaly
Thanks,
Please try again with below code.
Visualforce Page
No any change for class, change the constructor name same as apex class name.
Hi Mr Salesforce,
Does not check the if condition it check the else straightly, i want to add this page to formula field using HYPERLINK so i need to check the condition only in (javascript)visualforcepage , how do this?
Thanks.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello,
We are already using javascript in visualforce page, create a visualforce page which is in above message as well as create apex class.
For Hyperlink
- Go To --> Your Name --> Setup --> Create --> Objects
- Open your custom object "Visit__c"
- Click "New Button or Link"
Label - Link Label
Name - Link Name
Display Type - Detail Page Link
Behavior - Display in existing window with sidebar / Display in existing window without sidebar
Content Source - Visualforce Page
Content - Created Visualforce Page Name
Include created hyper link to the visit page layout.
Thanks,
Jigar