Jump to content
  • 0

Passing field values with ampersand (&) over query String


Question

3 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 post
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 post
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 post
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...