Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Verified Answer
+1
person also asked this
people also asked this
Replies
22 replies
Subscribers
7 subscribers
Views
8433 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
User Interface
with() declarations refresh on any user action regardless of connection
marky
over 8 years ago
Hello:
I have noticed that anything declared in a with will get refreshed on any action the user takes on an interface, even if the with is unrelated to the action (such as a summary section at the top of the screen and a comments text box at the bottom, with no connection between the two).
Is this expected behavior for Appian?
It seems like with declared variables/rules/components should only refresh if one of the input variables changes.
If you see in the attached interface, changing the value in the textbox is refreshing the with variable, even though they are not related.
OriginalPostID-251823
example_interface.txt
Discussion posts and replies are publicly visible
Top Replies
marky
over 8 years ago
+1
I already know how to refactor the code, so thank you for the suggestions. The problem is that I doubt more than 10% of Appian developers actually understand the way with() scope works. So I ask which…
Parents
0
chetany
A Score Level 1
over 8 years ago
@marky, you can use queryEntities in with() and still avoid un-necessary DB calls. You can check if the queryentity should really be evaluated within if().
an example: if(isnull(local!name), todatasubset({}), a!queryEntity(
) ). So, if the search criteria is not specified, the queryEntity will not evaluate.
I agree that ideally it should evaluate only if it is needed. But with() is meant to be "re-active".
To state a simplistic example:
load(
local!num1: 5,
local!num2: 7,
with(
local!addition: local!num1 + local!num2,
{/*..more code*/
}
)
)
now, in a "normal programming language", local!addition will not be updated even if values of local!num1 and local!num2 get updated. It will remain the same.
But, in case of with(), if value of local!num1 or local!num2 get updated, local!addition gets updated. That's called "reactivity". Check this link: https://en.wikipedia.org/wiki/Reactive_programming
Now, SAIL provides with() for reactive mechanism. In the example given, local!addition is dependent on local!num1 and local!num2, hence it need to be updated automatically if the values of its dependents change. This is sort of similar to event handlers in JavaScript. In this case , with() is "listening" for any changes to the values of any of the local!variables.
Now, I saw the code that you attached. You have a variable in with() declared like this:
local!refreshedVariable:1 + tointeger(rand() * (50)) . Now this variable is actually not dependent on any other local variable and hence ideally should not be re-evaluated - I see your point.
Seems like with() just re-evaluates even if any of the local variables used inside the with() block are saved into - these variables may not have been declared inside with() and may not be affecting the variable which needs to be re-evaluated.
I guess, determining if a local!variable should be re-evaluated or not is complicated. One reason I think is: even if such logic was developed, the SAIL interpreter would have to analyze the dependents of all local variables used in the UI, and would have run the same logic on each and every local variable and decide if it should be re-evaluated. It would slow down things on UI.. A UI needs to be re-active/having quick response time. Hence, its not worth implementing this complexity for with().. This is just my opinion.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
chetany
A Score Level 1
over 8 years ago
@marky, you can use queryEntities in with() and still avoid un-necessary DB calls. You can check if the queryentity should really be evaluated within if().
an example: if(isnull(local!name), todatasubset({}), a!queryEntity(
) ). So, if the search criteria is not specified, the queryEntity will not evaluate.
I agree that ideally it should evaluate only if it is needed. But with() is meant to be "re-active".
To state a simplistic example:
load(
local!num1: 5,
local!num2: 7,
with(
local!addition: local!num1 + local!num2,
{/*..more code*/
}
)
)
now, in a "normal programming language", local!addition will not be updated even if values of local!num1 and local!num2 get updated. It will remain the same.
But, in case of with(), if value of local!num1 or local!num2 get updated, local!addition gets updated. That's called "reactivity". Check this link: https://en.wikipedia.org/wiki/Reactive_programming
Now, SAIL provides with() for reactive mechanism. In the example given, local!addition is dependent on local!num1 and local!num2, hence it need to be updated automatically if the values of its dependents change. This is sort of similar to event handlers in JavaScript. In this case , with() is "listening" for any changes to the values of any of the local!variables.
Now, I saw the code that you attached. You have a variable in with() declared like this:
local!refreshedVariable:1 + tointeger(rand() * (50)) . Now this variable is actually not dependent on any other local variable and hence ideally should not be re-evaluated - I see your point.
Seems like with() just re-evaluates even if any of the local variables used inside the with() block are saved into - these variables may not have been declared inside with() and may not be affecting the variable which needs to be re-evaluated.
I guess, determining if a local!variable should be re-evaluated or not is complicated. One reason I think is: even if such logic was developed, the SAIL interpreter would have to analyze the dependents of all local variables used in the UI, and would have run the same logic on each and every local variable and decide if it should be re-evaluated. It would slow down things on UI.. A UI needs to be re-active/having quick response time. Hence, its not worth implementing this complexity for with().. This is just my opinion.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data