Jump to content
  • 0

Passing field values with ampersand (&) over query String


TroubleShooter

Question

8 answers to this question

Recommended Posts

  • 0

Hello @TroubleShooter,

 

The reason why the ampersand symbol is being cut is because Caspio renders the link literally. In this example:

<a href="https://www.google.com?myParameter=[@field:someField]"> Link </a>

 

If "someField" evaluates to "Some Value & Another Value" then the mark-up would result to 

<a href="https://www.google.com?myParameter=Some Value & Another Value"> Link </a>

 

This is when urlencoding comes into play. What this does is substitutes the special characters in a standard HTML format which interprets characters a different way.

 

You may try using my code snippet below.

1.) Just replace the link ID with the id attribute of your link.

2.) repeat the addParameter function as needed. The first argument is your parameter name, and the second argument is your field value.

<a href="#" id="link-1">MyLink</a>

<script>
// DO NOT TOUCH FROM THIS POINT
var params = []; 
addParameter = function(qs, val){
  params.push(`${qs}=${encodeURIComponent(val)}`);
}
//UP TO THIS POINT

var link_id = "link-1";
var base_url = "https://SomeDomainFrom.caspio.com/dp/926560as124321324dasd00a6523f123123624543123423fc0453b9093";
addParameter('boo', '[@field:SelectedAction]'); //repeat as needed
addParameter('far', '[@field:SelectedAction]');


  
// DO NOT TOUCH FROM THIS POINT
var queryString = params.join("&");
document.querySelector(`#${link_id}`).href = `${base_url}?${params.join("&")}`
//UP TO THIS POINT


</script>

 

Works for me.

 

-DN31337!

Link to comment
Share on other sites

  • 0

I need to ask another question about this. I don't know Javascript, but my links are not working because I have # in my addresses (for Apt Numbers).

Could you explain how I can escape # characters. I understand it's %23 and that I have to use encodeURIComponent().

This is my link

 

<a href ="[@app:URL_2]?cid=[@field:ID]&fn=[@field:FirstName]&ln=[@field:LastName]&a1=[@field:Address1]&a2=[@field:Address2]&c=[@field:City]&z=[@field:ZipPostalCode]&p1=@field:PrimaryPhone]&p2=[@field:SecondaryPhone]&da1=[@field:Address1]&da2=[@field:Address2]&dc=[@field:City]&dz=[@field:ZipPostalCode]&dp1=@field:PrimaryPhone]&dp2=[@field:SecondaryPhone]&r=[@field:Route]&dn=[@field:DriverNote]&pa=[@field:PhysicalAssistanceComment]&rc=[@field:Rate_Cd]&m=[@field:MobilityDevice]&cbResetParam=1">[@calcfield:1#]<a>

I am finding # in a1, a2, d1 d2.  I don't understand how to replace the  # in the code above.

Thanks for any help

 

Edited by Tonie
Found a problem, it's only working on the first line of a report, the later links are not working.
Link to comment
Share on other sites

  • 0

Hi @Tonie,

There is not need to specify the character which you would like to encoded in the code.

I assumed that you have a Tabular Report Datapage and created a code based on the link you have provided:

<a href="#" id="link-[@cbRecordIndex#]">[@calcfield:1#]</a>

<script>
// DO NOT TOUCH FROM THIS POINT
var params = []; 
addParameter = function(qs, val){
  params.push(`${qs}=${encodeURIComponent(val)}`);
}
//UP TO THIS POINT

var link_id = "link-[@cbRecordIndex#]";
var base_url = "[@app:URL_2]";

addParameter('cid', '[@field:ID]');
addParameter('fn', '[@field:FirstName]');
addParameter('ln', '[@field:LastName]');
addParameter('a1', '[@field:Address1]');
addParameter('a2', '[@field:Address2]');
addParameter('c', '[@field:City]');
addParameter('z', '[@field:ZipPostalCode]');
addParameter('p1', '[@field:PrimaryPhone]');
addParameter('p2', '[@field:SecondaryPhone]');
addParameter('da1', '[@field:Address1]');
addParameter('da2', '[@field:Address2]');
addParameter('dc', '[@field:City]');
addParameter('dz', '[@field:ZipPostalCode]');
addParameter('dp1', '[@field:PrimaryPhone]');
addParameter('dp2', '[@field:SecondaryPhone]');
addParameter('r', '[@field:Route]');
addParameter('dn', '[@field:DriverNote]');
addParameter('pa', '[@field:PhysicalAssistanceComment]');
addParameter('rc', '[@field:Rate_Cd]');
addParameter('m', '[@field:MobilityDevice]');
addParameter('cbResetParam', '1');

  
// DO NOT TOUCH FROM THIS POINT
var queryString = params.join("&");
document.querySelector(`#${link_id}`).href = `${base_url}?${params.join("&")}`
//UP TO THIS POINT


</script>

Regards,

Vitalikssssss

 

Link to comment
Share on other sites

  • 0
On 2/27/2020 at 8:24 AM, Vitalikssssss said:

Hi @Tonie,

There is not need to specify the character which you would like to encoded in the code.

I assumed that you have a Tabular Report Datapage and created a code based on the link you have provided:


<a href="#" id="link-[@cbRecordIndex#]">[@calcfield:1#]</a>

<script>
// DO NOT TOUCH FROM THIS POINT
var params = []; 
addParameter = function(qs, val){
  params.push(`${qs}=${encodeURIComponent(val)}`);
}
//UP TO THIS POINT

var link_id = "link-[@cbRecordIndex#]";
var base_url = "[@app:URL_2]";

addParameter('cid', '[@field:ID]');
addParameter('fn', '[@field:FirstName]');
addParameter('ln', '[@field:LastName]');
addParameter('a1', '[@field:Address1]');
addParameter('a2', '[@field:Address2]');
addParameter('c', '[@field:City]');
addParameter('z', '[@field:ZipPostalCode]');
addParameter('p1', '[@field:PrimaryPhone]');
addParameter('p2', '[@field:SecondaryPhone]');
addParameter('da1', '[@field:Address1]');
addParameter('da2', '[@field:Address2]');
addParameter('dc', '[@field:City]');
addParameter('dz', '[@field:ZipPostalCode]');
addParameter('dp1', '[@field:PrimaryPhone]');
addParameter('dp2', '[@field:SecondaryPhone]');
addParameter('r', '[@field:Route]');
addParameter('dn', '[@field:DriverNote]');
addParameter('pa', '[@field:PhysicalAssistanceComment]');
addParameter('rc', '[@field:Rate_Cd]');
addParameter('m', '[@field:MobilityDevice]');
addParameter('cbResetParam', '1');

  
// DO NOT TOUCH FROM THIS POINT
var queryString = params.join("&");
document.querySelector(`#${link_id}`).href = `${base_url}?${params.join("&")}`
//UP TO THIS POINT


</script>

Regards,

Vitalikssssss

 

How would this be done in a link from a details page?

Link to comment
Share on other sites

  • 0

@Vitalikssssss I am doing something very similar to what is described above as I am passing field values to a link on my web page to create an invoice.  Anytime there was a "#" included in an address, it would stop all the information following that point.  I have incorporated the code from above and it does pass it on, but now I am getting "%20" anywhere there should be a space and "%23" where the # is included.   Below is my code that I created from the examples above.  Do you see where I am creating this problem?  I'm hoping it's something obvious!

<a href="#" id="link-1">VIEW INVOICE</a> <script>
// DO NOT TOUCH FROM THIS POINT
var params = []; 
addParameter = function(qs, val){
  params.push(`${qs}=${encodeURIComponent(val)}`);
}
//UP TO THIS POINT

var link_id = "link-1";
var base_url = "https://janetrippe.com/invoice.html";
addParameter('fn', '[@field:FirstName]'); 
addParameter('ln', '[@field:LastName]');
addParameter('frn', '[@field:FarmRanchName]');
addParameter('ad1', '[@field:MailingAddress]');
addParameter('City', '[@field:City]');
addParameter('State', '[@field:State]');
addParameter('Zip', '[@field:Zip]');
addParameter('Phone1', '[@field:Phone1]');
addParameter('Phone1C', '[@field:Phone1Contact]');
addParameter('Phone2', '[@field:Phone2]');
addParameter('Phone2C', '[@field:Phone2Contact]');
addParameter('DA', '[@field:DeliveryAddress]');
addParameter('DC', '[@field:DeliveryDateComments]');
addParameter('DD', '[@field:BullDeliveryDate]');
addParameter('AAA', '[@field:AAAMemberCode]');
addParameter('Bid', '[@field:BuyerID]');
addParameter('TN', '[@field:TransferName]');
addParameter('Code', '[@field:AIMSid#]');

// DO NOT TOUCH FROM THIS POINT
var queryString = params.join("&");
document.querySelector(`#${link_id}`).href = `${base_url}?${params.join("&")}`
//UP TO THIS POINT

</script>

 

Here is a sample of what it is pulling; I have a # sign in the address as '4800 #1 Black Horse Pike'; it actually changed the # sign to %23 and the spaces to %20

Thanks so much for your help!!

Janet

image.png.f58de0ab336b48d7d98d9f009aff0779.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...