Hi
I'm trying to Generate a Random number to be used as application number. This application number depends on the category of application you choose from Drop Down.
If the request is of type "Application Training Request", then I'll add "APP" as prefix to the randomly generated variable.
If the request is of type "Service Support Request", then I'll add "SERV" as prefix to the randomly generated variable.
What I did so far:
1) Created a Variable and named it "VarRequestNumber" that gets initiated once screen loads
UpdateContext({VarRequestNumber:Text(Round(Rand()*10000,0),"[$-en]0000#")});
2) I used the following for OnSelect and OnChange properties of the request type dropbox:
Switch(DataCardValueRequestType.Selected.Value,
"Application Training Request",Concatenate("APP","-",VarRequestNumber),
"Service Support Request",Concatenate("SERV","-",VarRequestNumber))
3) For the Text Input, I used the put in the Default Value:
VarRequestNumber
My Challenge: The text is not updating. It just display the initially generate Random number, the value doesn't change.
What should I do to make the changes reflect as I change the request type?
Thanks in advance
Solved! Go to Solution.
This is one of the drawbacks of repeating the same formula in several places.
Please consider the following.
- In your OnVisible action of the screen, add the following formula:
Set(varRequestBase, Text(Round(Rand() *10000,0), "00000"))
- In the OnChange action of DataCardValueRequestType add the following formula:
With({_rnd: Text(Round(Rand() *10000,0), "00000")},
Set(varRequestNo,
Switch(Left(Self.Selected.Value,3)
"App", "APP" & "-" & _rnd,
"Ser", "SERV" & "-" & _rnd
)
)
)
- In the Default property of the Text Input for the request number, set the following formula:
Coalesce(varRequestNo, Parent.Default, varRequestBase)
-In the OnSuccess action of your form, set the formula to:
Set(varRequestNo, Blank())
The assumptions are the following:
1) You are using an EditForm and the Request number is part of your form and is a field value from your underlying record (thus the addition of the Parent.Default to the formula so that you can actually edit and retrieve the submitted request number)
2) That changing the RequestType should always generate a new random number based on the request type.
If all the above are true, then this should give you what you want.
@yjamous you have to use,
Set(VarRequestNumber, Concatenate("APP","-",VarRequestNumber))
Please consider changing your Formula to the following on the OnChange:
With({_rnd: Text(Round(Rand() *10000,0), "00000")},
Set(varRequestNumber,
Switch(Left(Self.Selected.Value,3)
"App", "APP" & "-" & _rnd,
"Ser", "SERV" & "-" & _rnd
)
)
)
You're not capturing the output of your formula in your original.
I hope this is helpful for you.
Hi @CNT I tried to do the following:
I used the following for OnSelect and OnChange:
Switch(DataCardValueRequestType.Selected.Value,
"Application Training Request",Set(VarRequestNumber, Concatenate("APP","-",VarRequestNumber)),
"Service Support Request",Set(VarRequestNumber, Concatenate("SERV","-",VarRequestNumber)));
And my text input is as shown below:
Still the number doesn't change in the text input
@yjamous Ooops! one is a Context variable and the other is a Global variable (with the same name!!!)
Change the OnVisible to
Set(VarRequestNumber, Text(Round(Rand()*10000,0),"[$-en]0000#"));
Please remember to give a 👍 and accept the solution as it will help others in the future.
Ok
I did the following:
I set the OnVisible as you suggested:
I changed OnSelect and OnChange for the dropdown and added a new variable:
Text Input Property:
Now, the text input doesn't change when I change the request type as shown below:
It's frustrating 😞
@yjamous Oh No! I only told you to change that Context variable in OnVisible to a global variable. Please do not change anything in the OnSelect. Now again we have 2 variables and the only difference is we have 2 global variables. We need only ONE variable. So please put the code back in the OnSelect as it was 25 minutes ago.
Now that I'm using one Variable it's not adding the prefix.
@yjamous Could you please share the code you have now in the onVisible and on OnSelect as a code snippet (not picture).
This is one of the drawbacks of repeating the same formula in several places.
Please consider the following.
- In your OnVisible action of the screen, add the following formula:
Set(varRequestBase, Text(Round(Rand() *10000,0), "00000"))
- In the OnChange action of DataCardValueRequestType add the following formula:
With({_rnd: Text(Round(Rand() *10000,0), "00000")},
Set(varRequestNo,
Switch(Left(Self.Selected.Value,3)
"App", "APP" & "-" & _rnd,
"Ser", "SERV" & "-" & _rnd
)
)
)
- In the Default property of the Text Input for the request number, set the following formula:
Coalesce(varRequestNo, Parent.Default, varRequestBase)
-In the OnSuccess action of your form, set the formula to:
Set(varRequestNo, Blank())
The assumptions are the following:
1) You are using an EditForm and the Request number is part of your form and is a field value from your underlying record (thus the addition of the Parent.Default to the formula so that you can actually edit and retrieve the submitted request number)
2) That changing the RequestType should always generate a new random number based on the request type.
If all the above are true, then this should give you what you want.
User | Count |
---|---|
121 | |
88 | |
88 | |
75 | |
66 |
User | Count |
---|---|
216 | |
180 | |
138 | |
96 | |
73 |