Page 1 of 1
How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 6:50 pm
by Clarkey
Hi folks, I'm new to Revolution and don't have a programming background, so please excuse the obvious newbie post (and this may well be the first of many!).
How do I work with text strings that contain double quotes? I want to use the urlencode function to prepare the data element for a POST command but the quotes in the data string are creating errors.
This must be a common problem but I'm obviously not searching on the correct term. So, any insights most appreciated.
Best,
Keith..
Re: How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 7:29 pm
by Klaus
Hi Keith,
what errors do you get and what did you script so far that causes the error(s)?
Best
Klaus
Re: How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 8:59 pm
by dunbarx
Perhaps you are asking how to add double quotes? Double quotes frame literals, and for that reason they are also a constant in Revolution, so if you say:
answer "xyz", you will get xyz.
But if you say answer quote & "xyz" & quote, you will get "xyz".
This is a way to embed quotes in a string, otherwise hard to get one's head around.
Or is that not the issue?
Craig Newman
Re: How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 9:03 pm
by Clarkey
Hi Klaus,
Thanks for responding. The post message I need to send contains double quotes - here is the example code:
Code: Select all
POST https://na1.salesforce.com/services/Soap/u/10.0 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol
1.1.4322.573)
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 510
Expect: 100-continue
Host: na1.salesforce.com
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:partner.soap.sforce.com">
<soapenv:Body>
<urn:login>
<urn:username>user@domain.com</urn:username>
<urn:password>secret</urn:password>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
My script currently looks like this:
Code: Select all
local tSalesforceURL --Salesforce login server
local tSalesforceUsername, tSalesforcePassword, tSalesforceSecurityToken --User credentials
local tSalesforceLoginMessage, tSalesforceLoginResult --Login POST message and result
global gSalesforceSessionId --Session ID returned following successful login
global gSalesforceMetadataServerUrl --Server for calls after login
put null into gSalesforceSessionId, gSalesforceMetadataServerUrl, tSalesforceLoginResult
on mouseUp
ask "Enter your Salesforce Username"
put it into tSalesforceUsername
ask "Enter your Salesforce Password"
put it into tSalesforcePassword
ask "Enter your Salesforce Security Token"
put it into tSalesforceSecurityToken
put "http//www.salesforce.com" into tSalesforceURL
put urlencode ("POST https://na1.salesforce.com/services/Soap/u/10.0 HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.573) Content-Type: text/xml; charset=utf-8 Content-Length: 510 Expect: 100-continue Host: na1.salesforce.com <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:urn="urn:partner.soap.sforce.com"><soapenv:Body><urn:login><urn:username>tSalesforceUsername</urn:username><urn:password>tSalesforcePassword</urn:password></urn:login></soapenv:Body></soapenv:Envelope>) into tSalesforceLoginMessage
post tSalesforceLoginMessage to URL "https://na1.salesforce.com/services/Soap/u/10.0"
Post field "Return Values" to URL field "Current Page"
end mouseUp
So, urlencode (or even put) commands interpret first double quote as the end of the statement and I then get compilation errors that the function separators are not commas.
Best,
Keith..
Re: How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 9:06 pm
by Clarkey
dunbarx wrote:Perhaps you are asking how to add double quotes? Double quotes frame literals, and for that reason they are also a constant in Revolution, so if you say:
answer "xyz", you will get xyz.
But if you say answer quote & "xyz" & quote, you will get "xyz".
This is a way to embed quotes in a string, otherwise hard to get one's head around.
Or is that not the issue?
Craig Newman
Craig, thanks for responding - as you can see, the issue is that I have double quotes residing within the literals. This is probably just Revolution naivety on my part as I'm trying to get my head around a whole new set of concepts here.
Best,
Keith..
Re: How to manage text strings that contain quotes
Posted: Mon Jun 14, 2010 10:39 pm
by Curry
You can escape quotes thusly:
put "blahblah" & quote & "blahblah" into myVar
You can add variables into the mix that way too.
Or you could put your post data into a container such as custom property or field, and:
put urlencode (the postData of this stack) into tSalesforceLoginMessage
Re: How to manage text strings that contain quotes
Posted: Tue Jun 15, 2010 7:35 am
by Clarkey
Thanks Curry, I slept on the problem and awoke thinking that maybe I should break the message payload content down into chunks to allow reuse and avoid the embedded quotes issue - and your first two lines hit the spot on how I might achieve this.
I can also see that the container approach has its merits though - placing the message content in off-card fields would help during development for maintenance. So, I think I'll end up with a hybrid of these.
Brilliant - thanks for the help.
Best,
Keith..