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
Kathleen LehnigkKathleen Lehnigk 

How to combine 2 custom buttons (1 x URL Hack, 1 x Javascript) into 1 button?

Hello everybody,

We've created a new object called Visit Reports in our org. After having created a meeting they will be able to click a button in order to create a new Visit Report record from there. I've created a custom URL-button for that in order to pass on certain values into the new Visit Report Record.

/a18/e?retURL={!Event.What}&CF00ND0000006ECXR={!Account.Name}&CF00ND0000006ECXR_lkid={!Account.Id}&00ND0000006ECXa={!Event.Description}&00ND0000006ECXb={!Event.Location}&00ND0000006ECXY={!Event.ActivityDate}&CF00ND0000006ECXf={!Contact.Name}&CF00ND0000006ECXf_lkid={!Contact.Id}&00ND0000006ECXg={!Contact.Name}&00ND0000006ECXU={!Event.Id}

Unfortunately this does not link the Meeting with the Visit Report record directly, which is why I've created another button on the newly created Visit Report. After clicking this (Javascript) button, the meeting record will be linked with the Visit Report record. For that I'm having an Activity ID field on the visit report record, which the button uses to link the 2 records.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

var EvObj = new sforce.SObject("Event");
var VR = new sforce.SObject("Visit_Report__c");

EvObj.Id = '{!Visit_Report__c.Activity_ID__c}';
EvObj.Visit_Report__c = '{!Visit_Report__c.Id}';
EvObj.WhatID = '{!Account.Id}';
var result = sforce.connection.update([EvObj]);
location.reload(true);

My question now is, whether you know of a nice & easy way to combine the 2 buttons into 1. So, that when you create the New Visit Report from the Meeting, it is automatically linked to the Meeting record.

I've used some code from some dev-website to create the Javascript-button. I'm not very knowledgable in this type of coding.

Thank you already in advance for any advice you can give in this matter.

Kathleen
Best Answer chosen by Kathleen Lehnigk
Kathleen LehnigkKathleen Lehnigk
Alright. I've now managed to do the second step (linking of Visit Report record to the Meeting) using Process Builder. 

Since I'm saving the Activity ID on the Visit Report record I can then do a relation lookup to the Visit Report Primary contact (= Primary contact of Meeting). By then comparing the Activity ID on the Visit Report Record and the existing Meeting IDs on that specific contact record it now links the two together.

All Answers

pconpcon
You can set the location to be the value of your link above instead of saying locaion.reload.
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

var EvObj = new sforce.SObject("Event");
var VR = new sforce.SObject("Visit_Report__c");

EvObj.Id = '{!Visit_Report__c.Activity_ID__c}';
EvObj.Visit_Report__c = '{!Visit_Report__c.Id}';
EvObj.WhatID = '{!Account.Id}';
var result = sforce.connection.update([EvObj]);

document.location.href = "/a18/e?retURL={!Event.What}&CF00ND0000006ECXR={!Account.Name}&CF00ND0000006ECXR_lkid={!Account.Id}&00ND0000006ECXa={!Event.Description}&00ND0000006ECXb={!Event.Location}&00ND0000006ECXY={!Event.ActivityDate}&CF00ND0000006ECXf={!Contact.Name}&CF00ND0000006ECXf_lkid={!Contact.Id}&00ND0000006ECXg={!Contact.Name}&00ND0000006ECXU={!Event.Id}";

NOTE: This code has not been tested and may contain typographical or logical errors
Kathleen LehnigkKathleen Lehnigk
Hi pcon,

Thank you for your reply. Unfortunately your solution does not work. The 2 buttons are currently shown on 2 separate objects. The first one on the Meeting record and the second (where it's using the Javascript and doing the linkage between the 2 records) on the created Visit Report. The button would have to be on the Meeting record only, before the Visit report is created.
pconpcon
So, let's back up.  What is it exactly that you are trying to accomplish with this button?  You are trying to automatically create the Visit_Report__c object from the Meeting page (is this a custom object or a standard object renamed)?  How are the Visit_Report__c and the Meeting linked?  In the JavaScript above it appears that the Event (I'm assuming this is your "Meeting" object) has a lookup feild for a Visit_Report__c
Kathleen LehnigkKathleen Lehnigk
Alright. I've now managed to do the second step (linking of Visit Report record to the Meeting) using Process Builder. 

Since I'm saving the Activity ID on the Visit Report record I can then do a relation lookup to the Visit Report Primary contact (= Primary contact of Meeting). By then comparing the Activity ID on the Visit Report Record and the existing Meeting IDs on that specific contact record it now links the two together.
This was selected as the best answer
Kathleen LehnigkKathleen Lehnigk
But thanks for your help with this. :-)