Coldfusion : Odd Output of Timestamp : Replaces with an x - coldfusion

I think my timestamp needs to be at the end of the string. But when I move it there - I get an odd output of the &times turns into an x. Is there a fix for this? At the front it works fine.
<cfset usem = "timestamp=#unixdatetimeNow.getTime()#&symbol=#pair#&side=#side#&type=#type#&quantity=#size#">
Outputs :
timestamp=1645552579468&symbol=SHIBUSDT&side=sell&type=market&quantity=9005
<cfset usem = "symbol=#pair#&side=#side#&type=#type#&quantity=#size#&timestamp=#unixdatetimeNow.getTime()#">
Outputs with the x :
symbol=SHIBUSDT&side=sell&type=market&quantity=9005×tamp=1645552579468
How do I fix this x replacement? Does it in both cfset and in script

Update: 2022-04-06
TLDR; Bottom line, nothing needs to be done. As mentioned in the comments, and your other thread ColdFusion : Binance API : Not all sent parameters were read, the parameter name is still &timestamp, it just appears to be xtamp when displayed on screen.
It's because the substring &times is being treated as the html entity &times, which gets rendered as the symbol x.
Why is [timestamp] fine at the front but not back?
When timestamp is the first parameter in the query string, there's no & preceding "time". So it's not treated as an html entity.
Keep in mind this is just a presentation issue. The substring &time is only rendered as x when you output the variable. The actual contents of the variable don't change. So nothing happens its used in your cfhttp call:
// sends "&timestamp" not "xstamp"
cfhttp(....) {
...
cfhttpparam(type="body", value="#yourString#");
}
Fixed with : & : <cfset usem = "...&timestamp=#unixdatetimeNow.getTime()#">
That might display correctly on screen, but will break your cfhttp call because it sets the parameter name to the literal string &timestamp but the API is expecting a parameter named timestamp.

Related

RDL 2016 Report Builder skip a line for an optional parameter

I have an RDL template which contains of several parameters. They are all optional and marked:
Allow Null Value
Allow Blank Value ("")
It is important that they are optional since sometimes the address does not contain AddressLine3 (or in fact AddressLine1 or AddressLine2, or even PostCode):
They are all dropped together in one textbox area, and it all works well, but the problem is if I don't pass one of the optional params (AddressLIne2 in the example below) - an empty line is preserved in the report:
Any ideas on how to make that empty line disappear?
The easiest way to do this is to replace the list of 5 parameters with a single expression. Something like this.
=
Parameters!FullName.Value & IIF(IsNothing(Parameters!FullName.Value), Nothing, vbcrlf) &
Parameters!AddressLine1.Value & IIF(IsNothing(Parameters!AddressLine1.Value), Nothing, vbcrlf) &
Parameters!AddressLine2.Value & IIF(IsNothing(Parameters!AddressLine2.Value), Nothing, vbcrlf) &
Parameters!AddressLine3.Value & IIF(IsNothing(Parameters!AddressLine3.Value), Nothing, vbcrlf) &
Parameters!PostCode.Value
This simply concatenates each parameter value with a new line added only if the parameter was not empty.
Demo data
The following shows the same principle applied to some address data from the sample AdventureWorks database
The report shows all address fields for illustration
Which gives the following output

What is wrong with my Power BI query (using a parameter)?

I'm brand new to using PBI but as far as I can tell, I should be able to substitute a parameter as part of a Direct Query in place of a hard-coded variable...ie
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo "& home_name]),.....
instead of
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo 'NAME OF HOME'"]),...
However, the parameter-included version just says
DataSource.Error: Microsoft SQL: Incorrect syntax near 'House'.
Details:
DataSourceKind=SQL
DataSourcePath=NAMEOFDB;CMUtility
Message=Incorrect syntax near 'House'.
Number=102
Class=15
"House" is the currently - assigned last word of the home_name variable. What have I done wrong?
PS - I have surmised that I shouldn't need the extra & at the end of the parameter, as I'm not adding anything else to the query, but even with both &s it still doesn't work.
The type of your parameters is text. In SQL, text literals must be quoted, i.e. sp_get_residentsinfo 'NAME OF HOME', but the statement build by you is sp_get_residentsinfo NAME OF HOME.
You should use Text.Replace to escape single quotes in the parameter's value and append a quote before and after it.

Autohotkey if statement not working, no error msg

I'm trying to use autohotkey to gather a chuck of data from a website and then click a certain spot on the website depending on what the text is. I'm able to get it to actually pick up the value but when it comes to the if statement it won't seem to process and yields no error message. Here is a quick sample of my code, there is about 20 if statement values so for brevity sake I've only included a few of the values.
GuessesLeft = 20
Errorcount = 0
;triple click and copy text making a variable out of the clipboard
;while (GuessesLeft!=0) part of future while loop
;{ part of future while loop
click 927,349
click 927,349
click 927,349
Send ^c
GetValue = %Clipboard%
if ( GetValue = "Frontal boss")
{
click 955,485
Guessesleft -= 1
}
else if ( GetValue = "Supraorbital Ridge")
{
click 955,571
Guessesleft -= 1
}
;....ETC
else
{
Errorcount += 1
}
;} part of future while loop
Any tips on what I might be doing wrong. Ideally I'd use a case statement but AHK doesn't seem to have them.
Wait a second -- you are triple clicking to highlight a full paragraph and copying that to the clipboard and checking to see if the entirety of the copied portion is the words in the if statement, right? And your words in the copied portion have quotes around them? Probably you will have to trim off any trailing spaces and/or returns:
GetValue = % Trim(Clipboard)
If that doesn't work, you may even have to shorten the length of the copied text by an arbitrary character or two:
GetValue = % SubStr(Clipboard, 1, (StrLen(Clipboard)-2))
Now, if I am wrong, and what you are really looking for is the words from the if statement wherever they may be in a longer paragraph -- and they are not surrounded by quotes, then you will want something like:
IfInString, Clipboard, Frontal boss
Or, if the quotes ARE there,
IfInString, Clipboard, "Frontal boss"
Hth,

convert string to variable coldfusion

I'm a bit stumped on this one..
I currently have a string.
Please enter your variable.firstname here
What i would like to do is find the variable.firstname in the string and convert it to be used as #variable.firstname#
Im using CF8, and ive looked at using findNoCase() but the variable.firstname portion can appear anywhere. I am also trying to use this in a Coldfusion Custom Tag as its to simply display the firstname of the user that could be dynamically populated.
I cant use any other functionality to change it IE = variable['firstname] because the variable could be the result of a dynamic variable i pass in and the query for the content will reside within the custom tag.
<cfset yourNewString = replace(yourOldString,'variable.firstname',
'##variable.firstname##', 'all')>
Note the double pound signs.
I cant use any other functionality to change it IE =
variable['firstname] because the variable could be the result of a
dynamic variable i pass in and the query for the content will reside
within the custom tag.
I'm not sure I understand exactly what you're saying here but if you're saying that variables.firstname is coming from another variable and the .firstname is the dynamic part you could still use array notation.
<cfset myName = "Travis">
<cfset yourName = "user125264">
<cfset myCustomVariable = "myName">
<cfoutput>Hi, My name is #variables[myCustomVariable]#. </cfoutput>
<cfset myCustomVariable = "yourName">
<cfoutput>Your name is #variables[MyCustomVariable]#.</cfoutput>
Output: Hi, My name is Travis. Your name is user125264.
If that isn't what you meant, I apologize.
If you're trying to replace variable.firstname with #variables.firstname# and then also get the value of that variable, you'll need to do the replace <cfset yourNewString = replace(yourOldString,'variable.firstname',
'##variables.firstname##', 'all')> and then wrap the resulting string in an evaluate() function (and an inner de() to prevent CF from evaluating everything): <cfset evaluatedString = evaluate(de(yourNewstring))>.
If there are more variables besides variable.firstname that need this kind of translation, you'll need to get into regex with reReplace() to catch them all in one statement. My regex is rusty, so you'll need to Google that bit on your own. ;o)

Determining if a string is not null/blank and is a number and not 0?

I normally don't work in ColdFusion but there's a FTP process at work I have to create a report for with the only option right now being a ColdFusion 8 server. This FTP feed has a few issues (trash too).
So, I make the query and then I need to convert some of the string values during the output to do some math. Before that:
How do I tell if a field in the output loop: is not blank or null, is string that can be converted into a valid number, and is not 0?
Is there a simple way of doing this w/o a lot of if statements?
Thanks!
So you want to make sure that the variable is numeric but not zero?
Then you want this:
<cfif IsNumeric(MyVar) AND MyVar NEQ 0 >
Determining if a string is not null/blank and is a number and not 0?
Here's the code I would use in this case.
<cfif isDefined(stringVar) and len((trim(stringVar))) and isNumeric(stringVar)>
do stuff here
</cfif>
isDefined returns a true if the variable exists. If you know the scope of the variable, i.e., its in the form or url scope for instance, you can use structkeyExists(form,"stringVar"). I would recommend using this approach if you know the scope of the variable.
Len(trim(stringVar)) is the second check. First off it trims any leading or trailing empty spaces from the string - this makes sure that any empty variables are not passed along. Then if something is there it will return the length of the string. If its empty len will return a 0.
isNumeric(stringVar) returns a true if the variable is a number and false otherwise.
<cfif Len(field) and Val(field)>
Len() will verify the field has length (not blank--there are no NULLs in CF) and Val() will automatically convert the first character in the string into into a number--or return 0 if it cannot.
Take note of Peter's comment below; although this is the least verbose answer, Val() may fail in certain edge conditions below, ie. The field is a string but starts with a number, incorrectly converting it to a number, and evaluating to TRUE.
<cfif isNumeric(myfield) and myfield gt 0>