JSON.stringify() and JSON.parse() seem to break calculated value scripts in RTC. How do I use JSON in calculated values?
Hi
I am tinkering with 'calculated values' in RTC trying to customize the behavior. I thought I'd store information as a JSON object in a 'Large String' custom attribute. However, it seems that as soon as I try to reference any of JavaScripts built in JSON functions the script no longer works.
For example, this script does not work. But it does print out "{}" in the console showing that the JSON function works.
The behavior is the same regardless of where I reference JSON. 'var a = JSON' anywhere will break it.
I do not get any errors when trying this as opposed to if the code contains null references.
Has anyone else encountered this problem?
Thank you for your time :)
I am tinkering with 'calculated values' in RTC trying to customize the behavior. I thought I'd store information as a JSON object in a 'Large String' custom attribute. However, it seems that as soon as I try to reference any of JavaScripts built in JSON functions the script no longer works.
For example, this script does not work. But it does print out "{}" in the console showing that the JSON function works.
dojo.provide("test_script"); console.log(JSON.stringify({}));When I comment out the JSON parts it works fine:
(function() {
dojo.declare("test_script", null, {
getValue: function(attribute, workItem, configuration) {
return "test script output";
}
});
})();
dojo.provide("test_script"); //console.log(JSON.stringify({}));
(function() {
dojo.declare("test_script", null, {
getValue: function(attribute, workItem, configuration) {
return "test script output";
}
});
})();
The behavior is the same regardless of where I reference JSON. 'var a = JSON' anywhere will break it.
I do not get any errors when trying this as opposed to if the code contains null references.
Has anyone else encountered this problem?
Thank you for your time :)
One answer
After googling for a bit I realized that I needed to import JSON from dojo. The following scripts works:
dojo.provide("test_script"); require(["dojo/json"], function(JSON){ console.log(JSON.stringify({}));I'll Just leave this here in case anyone else has the same problem.
dojo.declare("test_script", null, {
getValue: function(attribute, workItem, configuration) {
return "test script output";
}
});
});