refreshCalcFileds async mode

I am trying to use ExampleType.refreshCalcFields({async:false}) to refresh the fields and check their values in jasmine tests. However async mode doesn’t seem to have any effect. In the absence of any wait (which is done currently by sleep, and I am planning to change it to use waitForJob).

Is there a setting in environment to make this work in synchronous mode ? I have looked for if AsyncProcessingDisabled is set to true, but didn’t find that entry in our TenantConfig.

I’m not sure what you mean by “doesn’t have any effect”. We have tests that would say otherwise. What is it that makes you say it has no effect?

@kkommera If you are running refreshCalcFields({async:false}) and the fields aren’t updating, then there are 2 probable causes:

  1. Your data is not setup correctly. You should verify that there really is data loaded at the path specified by your stored calc.
  2. Your stored calc expression is not correct, you should verify that your expression really walks traverses the datamodel in the way you want (kind of paired with #1)

I use this api very frequently, both in tests and in real environments, and it has always worked.


Following up on Riley’s suggestion, I commonly debug my stored calcs with:

MyType.evaluate({filter: "id=='myRecordId'", projection: "'myCalcExpression'"})

1 Like

@rileysiebel Thank you. I think the data and expressions are correct, because eventually after the sleep time(10 seconds)or so, the data does appear in the stored calc fields. I was just trying to avoid using the sleep and instead use async = false , that way the fields are refreshed synchronously.

@trothwein Most of the tests fail when I remove sleep stmts.
Also the values printed in jasmine tests tells us what the values were when test was run.

And actually I should have mentioned, that I am working on the newer version of platform 7.9. Could that be why?

@sean.summers Thank you.

Hey @kkommera
Hope all is well!
In case this is helpful as well, sometimes these fields in the FetchSpec Type are handy when you want to force the refreshing of calc fields while reading the records in a type:

@kkommera Can you file a ticket with a branch and a test in that branch that fails if you set async to false and remove the sleeps? I have a number of tests that rely on that mode working so I’m guessing there is something else affecting this (perhaps the stored calcs depend on stored calcs in some referenced types?)

Does your stored calc expression depend on another stored calc or some other value that is populated asynchronously? ExampleType.refreshCalcFields({ async: false }) won’t produce the final value if the the upstream dependencies have not been set yet.

Hey Bus ! Good to hear from you, all good here.
We are using that in fetchSpec in different place. So, yeah I could try that here. But for a different reason the code was already modified by another developer to remove the calc field. I will test it though when I get a chance.

@matt, Thank you. No it is not dependent on another stored calc. It is depended on avalue that is populated right within the test.