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
j_wennerj_wenner 

s-control to copy the Billing Address to the Shipping Address

I am new to s-controls and need to build an s-control to copy the Billing Address to the Shipping Address on the Account object.   Please advise.
 
thx
Jeanette
 
gmc74gmc74
How do you want this to work?  Is this a button that is pushed?  If so, I would go with a URL instead of an S-Control
j_wennerj_wenner

Yes, I would like it to be a button that is pushed.

Can you send me the URL code that I would need to accomplish this task?

gmc74gmc74

I can't send you the code, since I can't see your screen, but I can point you in the correct direction

Create a new button  Setup > App Setup> Customize > Accounts > Buttons and Links

Select Detail Page Button,  Display in existing window with out header or sidebar

 

Down at the bottom, start with

 
Change the Case.Id to be Account.ID, then view the source code of the Account page when in edit mode and instead of &cas7=Taken, replace the cas7 with the field id, on my account screen it is acc17street, and replace Taken with the field value, which for Shipping Address should be - {!Account.ShippingAddress}
 
Do the same for each field until you have all the fields done, and add the &save=1 to the end to auto save the field.
 
if  you were just going to move the shipping address to the billing address, this would work -
 
 
If you had additional fields it would be like this -
 
 
The InputValueForCity would be the input id in the page source, and the FieldNameForCity would be the Salesforce Field Name that you want to replace it with
 
hemmhemm
Unless you are doing this in mass, this is already built in. Edit an Account and you'll see a "Copy Billing Address to Shipping Address" link just above the Shipping Address.
j_wennerj_wenner

In my sandbox, I tried the following code in a Detail Page Button with "Display in new window" and "URL" selected:

 

https://tapp0.salesforce.com/{!Account.Id}/e?retURL=%2F{!Account.Id}&ShippingStreet={!Account.BillingStreet}&ShippingCity={!Account.BillingCity}&ShippingState={!Account.BillingState}&ShippingPostalCode={!Account.BillingPostalCode}&save=1

 

It opens up a new window but does not do the copy as expected.  :(   Please advise.

j_wennerj_wenner
We are actually using custom Billing Address and Shipping Address fields.  But, I wanted to get this to work in the sandbox on the standard fields before trying to do this on the custom fields.
hemmhemm
Personally, I'd use either the AJAX Toolkit or Leverage how Salesforce does it with hte built in piece.  Using a URL can be problematic because of the Street field which can be multi-line.  The URL could still work, though.

Below is what's behind that link I told you about.  Maybe you can chase down where that exists in Salesforce's own JavaScript files and leverage that.


Code:
javascript: copyAddr('acc17street', 'acc17city', 'acc17zip', 'acc17country', 'acc17state', 'acc18street', 'acc18city', 'acc18zip', 'acc18country', 'acc18state', true, true)

 

j_wennerj_wenner

I changed my button to "execute javascript" and copied/pasted the following code example from you posting and changed the names of the fields appropriately:

javascript: copyAddr('Shipping_Address__c', 'Shipping_City__c', 'Shipping_State__c', 'Shipping_Zip_Code__c', 'Billing_Street__c', 'Billing_City__c', 'Billing_State__c', 'Billing_Zip_Code__c', true, true)

 

When I click on the button it throws an error stating:

"A problem with the OnClick JavaScript for this button  or link was encountered"

'javascript' is undefined

 

Please advise.   I am new to these buttons and links and need much guidance.

thx :)

j_wennerj_wenner
There's got to be some simple button/link code out there to copy one field value to another field (and how to set it up JavaScript or URL - opening a new window).  
 
If I have that code sample, then I can modify it to do what I need. 
 
But I can't seem to find that simple example anywhere.  :(   Please advise.
 
gmc74gmc74
The sample that I posted works, but I think you are replacing the html form field with the actual database field name.
 
 
Did you try the example one for the Billing Street?  That shouldn't have needed any modification to work. 
 
When you are looking at the URL after the & sign, the first item there is the input id.  To get that, open your account screen in edit mode, go to the view menu of your browser and choose Source (or Page Source).  Search for the field name that you are looking for and you should see something like -
<label for="acc17street">Billing Street</label>
the part in quotes is the name of the field you want to insert the Mailing Address into.
j_wennerj_wenner

I tried your suggestion and viewed the source of the edit screen on Account and found the following:

<label for="00N300000017WV9"><span class="requiredMark">*</span>Mailing Street</label>

 

I would assume that I would have found "Billing_Street__c" in the "label for=" section since that is the field name in the database.  The id shown above seems unique to that particular Account record. 

I want to make this s-control button generic enough to work on whatever Account record you happen to be viewing.   Please advise.

gmc74gmc74
You won't find Billing_Street__c because that is the database name, what ever the name of the field is on the edit screen, is what you will find.

If you were putting data in the Mailing Street field then the code would be

00N300000017WV9={whateverFieldYouAreInserting}
j_wennerj_wenner

I tried doing that exact thing with the following code:

javascript&colon; copyAddr('00N300000017U1C', '00N300000017U1H', '00N300000017U1b', '00N300000017U1M', '00N300000017WV9', '00N300000017WVE', '00N300000017WR3', '00N300000017WVJ', true, true)

 

When I click on the button it still throws an error stating:

"A problem with the OnClick JavaScript for this button  or link was encountered"

'javascript' is undefined

 

hemmhemm
Sorry.  Remove the javascript&colon; part and just have your button start with CopyAddr(...


j_wennerj_wenner

I did that and now I get the following error:

"A problem with the OnClick JavaScript for this button  or link was encountered"

'document.getElementByID(...)' is null or not an object
 
 
My code now looks like this:
 
copyAddr('00N300000017U1C', '00N300000017U1H', '00N300000017U1b', '00N300000017U1M', '00N300000017WV9', '00N300000017WVE', '00N300000017WR3', '00N300000017WVJ', true, true)
rpr2rpr2
Throwing out an alternative approach that I used for this same functionality -- I used workflow rules and field updates.  If the billing address and shipping address is different, then they each get filled in manually.  If they are the same, the billing address is entered and the shipping address is left blank.  When the record is saved, workflow rules fire and field updates are used to populate the shipping address with the value of the billing address.
j_wennerj_wenner
That works great, except for updating the state fields which are all picklists.   You can't update one picklist field with another picklist field's value thru a workflow - field update.   Known issue with SFDC Support.   :(