It's all about the answers!

Ask a question

JSON.stringify() and JSON.parse() seem to break calculated value scripts in RTC. How do I use JSON in calculated values?


Axel Ulmestig (34410) | asked Dec 16 '15, 4:34 a.m.
edited Jan 04 '16, 3:25 a.m.
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.
dojo.provide("test_script");

console.log(JSON.stringify({}));

(function() {
dojo.declare("test_script", null, {
getValue: function(attribute, workItem, configuration) {
return "test script output";
       }
    });
})();
When I comment out the JSON parts it works fine:

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



permanent link
Axel Ulmestig (34410) | answered Dec 16 '15, 5:47 a.m.
edited Jan 04 '16, 3:25 a.m.
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({}));
dojo.declare("test_script", null, {
getValue: function(attribute, workItem, configuration) {
return "test script output";
       }
    });
});
I'll Just leave this here in case anyone else has the same problem.

Your answer


Register or to post your answer.