Hello,
I have the following problem. If I run this snippet Uploading: image.png…
I get the correct results, which is the last 16 characters of the string " collection number is Opkrævning blev dannet - Collection: 1061190004472717"
However, if I run it like so, using a variable I captured a string in, it will not do slice, I will have the original string not sliced in $collectionNumber variable and I don’t understand why.
Hello, thanks for the answer but it’s not working. I don’t get it, it works fine if I set it up in a simple test, but in this long test it just refuses to work
Strange that it’s not working for you. I even copied the actual text and it worked for me.
You could try a different approach to get the collection number by using the string method split which creates an array from a string split on a given character. This assumes that the text you are checking is always in the same format as your example.
Add these two lines to the test to see if it works. I’m assuming the cellValue variable contains the text Opkrævning blev dannet - Collection: 1061190004472732
[info] Executing: | runScript | arr = '${cellValue}'.split(':'); return arr[1].trim() | newVal |
[info] Expand variable 'arr = '${cellValue}'.split(':'); return arr[1].trim()' into 'arr = 'Opkrævning blev dannet - Collection: 1061190004472732'.split(':'); return arr[1].trim()'
[info] Store '1061190004472732' into 'newVal'
[info] Executing: | echo | ${newVal} | |
[info] Expand variable '${newVal}' into '1061190004472732'
[info] echo: 1061190004472732
This splits the string on the colon into a two element array where the last element is the collection number. We trim the returned string to get rid of the leading space.
I tried that version as well, indeed if I replace the variable with the actual string ’ example string’ it works just fine.
I have no clue as to why it behaves like this.
As I posted above, if I run the same lines in a separate test on a different frame, I get the expected results.
It just refuses to store the sliced/split value. Maybe I should use
i find it confusing that sometimes you address a variable by its name, and other times you address it using ${variable}. Why not be consistent and use the same notation everywhere?
thanks for answering, however I get error in the browser console when I try to do console.log(new.Val)
Uncaught SyntaxError: Unexpected identifier
and windo.newVal outputs the same result
And using window.whatever does not seem to alter my result at all.
Can you confirm that ${tempVal} is enclosed with single apostrophes ' and not the fancy curly ones? It might just be the way this forum formats text but it looks like the apostrophes are ‘${tempVal}’ as opposed to '${tempVal}'
Failing that, could you try enclosing the variable name in double-quotes "${tempVal}".slice(-16)
yep, simple ones ‘${tempVal}’, looks like the forum is converting them to the ’ fancy ones.
double quotes does nothing
thanks for trying to help, i’ll keep trying