Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi
I am setting following variable in the script:
SET vYearChooseCP = Year( Today() ); |
SET vYearChoosePY = Year( Today() )-1;
SET vMaxDatePY = Makedate($(vYearChoosePY),num(month($(vMaxCalendarDate)),day($(vMaxCalendarDate));
In my visualization, I am changing the first two variables and it works fine (the formulas in the script are used to get the initial values, before the user makes changes).
However, the second variable does not work. I think the writing is wrong, but can't figure our which one.
Please, help.
Thank you!
Let= sets an EXISTING variable to the value
Set= creates a variable and sets it to the string literal
In your case, using set will STILL expand the $ sign, the trick is to work around the $ sign when assigning the variable
you can do this which means you can just call the variable as normal:
set v_variable1 = sum(Value) - #(v_variable2);
let v_variable1 = replace(v_variable1,'#','$');
Or this which would require you to dollar sign expand the variable
let v_variable1='sum(Value) - '&'$'&'(v_variable2);';
LET vYearChoosePY = Year( Today() )-1;
LET vMaxDatePY = Makedate($(vYearChoosePY),num(month($(vMaxCalendarDate),0),day($(vMaxCalendarDate));
Thank you for correction in NUM, my mistake. And for the link as well.
I have two question though (even after I read majority of the topics and the link you provided):
1. When I set a variable in the script through LET, it does not store the formula, right? When I then change the variable through extension in application, it does change the value from the one assigned in the script to the one I change it to, right? When I do so, I don't see the change in the Variables section, but I do see a change in the Text object referenced to this variable. This is just for my understanding that it is intended to work like this.
2. When I want to put the formula in the variable and I want it to stay dynamic, I need to use SET function, as per your link. So I ended up with the following script:
LET vYearChooseCP = Year( Today() ); |
LET vYearChoosePY = Year( Today() )-1;
SET vMaxDatePY = Makedate( $(vYearChoosePY),num( month($(vMaxCalendarDate)),0),day($(vMaxCalendarDate)));
'$(vYearChoosePY)'
So when I change vYearChoosePY in my app, the vMaxDatePY does not change. In the Variable section, it is shown as static number (in my example, 2016), whereas I intended to load it as a link to variable ($(vYearChoosePY)).
Let= sets an EXISTING variable to the value
Set= creates a variable and sets it to the string literal
In your case, using set will STILL expand the $ sign, the trick is to work around the $ sign when assigning the variable
you can do this which means you can just call the variable as normal:
set v_variable1 = sum(Value) - #(v_variable2);
let v_variable1 = replace(v_variable1,'#','$');
Or this which would require you to dollar sign expand the variable
let v_variable1='sum(Value) - '&'$'&'(v_variable2);';
oh k,
if you want to use a variable in your script then define it with LET
To use variables in the frond end we use SET; but they must always have a $() expansion otherwise they won't evaluate.
They below works for me in the front end
SET vYearChooseCP = Year( Today() ); |
SET vYearChoosePY = Year( Today() )-1;
SET vMaxDatePY = Makedate($(vYearChoosePY),12,1);
example $(vMaxDatePY ) returns = 1-12-2016
how are you changing vYearChoosePY in the app? if you are changing this in the app, what is the purpose of defining it in the load script?
Gleb Aitov wrote:
LET vYearChooseCP = Year( Today() ); LET vYearChoosePY = Year( Today() )-1;
SET vMaxDatePY = Makedate( $(vYearChoosePY),num( month($(vMaxCalendarDate)),0),day($(vMaxCalendarDate)));
'$(vYearChoosePY)'
So when I change vYearChoosePY in my app, the vMaxDatePY does not change. In the Variable section, it is shown as static number (in my example, 2016), whereas I intended to load it as a link to variable ($(vYearChoosePY)).
I am assuming that vYearChoosePY is being set with a default in the load script but then will become dynamic in the front end (no harm in this).
The issue comes in that vMaxDatePY is being defined in the load script and vYearChoosePY is being calculated and assigned at this point, so future changes in the front end won't change the formula.
Which is why you require one of the solutions I provided
let v_variable1='sum(Value) - '&'$'&'(v_variable2);';
OMG, now I understand. That worked, thanks.
... vYearChoosePY is being set with a default in the load script but then will become dynamic in the front end (no harm in this)...
Absolutely correct.