dynamic model formula field

I’m creating a dynamic model with javascript for a custom component, and getting an error:  “Unable to load Model(s) - JSON deserialization failed: Illegal value for primitive”

I think it has to do with the way I’m attempting to create ui-only formula fields in the model. Can someone take a look?

var timerModel = new mm();<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.objectName = 'Process_Log__c';<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.id = "Timer";<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.doQuery = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.preventUnloadIfUnsavedChanges = false;<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.recordsLimit = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; timerModel.fields = [<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 'Start',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uiOnly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displaytype: 'DATETIME',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ogdisplaytype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: 'Start',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultvaluetype: 'fieldvalue',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultValue: 'NOW',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readonly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 'ElapsedMinutes',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uiOnly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readonly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displaytype: 'FORMULA',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ogdisplaytype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: 'Elapsed Minutes',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype: 'DOUBLE',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; precision: 3,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale: 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: [{formula: '(NOW() - {{Start}}) / (1000*60)'}]

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 'ElapsedSeconds',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uiOnly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readonly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displaytype: 'FORMULA',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ogdisplaytype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: 'Elapsed Seconds',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype: 'DOUBLE',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; precision: 2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale: 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: [{formula: '({{ElapsedMinutes}} - FLOOR({{ElapsedMinutes}}))*60'}]

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 'PrettyTime',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uiOnly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readonly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displaytype: 'FORMULA',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ogdisplaytype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: 'Pretty Time',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: [{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: 'FLOOR({{ElapsedMinutes}})+":"+IF(LEN(ROUND({{ElapsedSeconds}})) = 1 ,'+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' "0"+ROUND({{ElapsedSeconds}}) , ROUND({{ElapsedSeconds}}))'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }]

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 'Color',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uiOnly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readonly: true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displaytype: 'FORMULA',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ogdisplaytype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: 'Color',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype: 'TEXT',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: [{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formula: 'IF({{ElapsedMinutes}}&gt;'+mintues3+', "'+color3+'",'+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' IF({{ElapsedMinutes}}&gt;'+minutes2+', "'+color2+'",'+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' IF({{ElapsedMinutes}}&gt;'+minutes1+', "'+defaultColor+'","'+color1+'")))'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; ];&nbsp;


Where have I gone wrong?

Nevermind!

I was making the syntax for the formulas more complicated than it needed to be. Here’s the working result:

<pre alt="" title="" name="" value="" type="" target="" rel="">var timerModel = new mm();
        timerModel.objectName = 'Process_Log__c';
        timerModel.id = "Timer";
        timerModel.doQuery = true;
        timerModel.preventUnloadIfUnsavedChanges = false;
        timerModel.recordsLimit = 0;
        // timerModel.createRowIfNoneFound = true;
        timerModel.fields = [
            { 
                id: 'Start',
                accessible: true,
                createable: true,
                defaultValue: "NOW",
                defaultvaluetype: "fieldvalue",
                displaytype: "DATETIME",
                editable: true,
                evaluatedDefaultValue: "NOW",
                label: "Start",
                uiOnly: true,
            },
            { 
                id: "ElapsedMinutes",
                accessible: true,
                calculated: true,
                createable: false,
                displaytype: "DOUBLE",
                editable: false,
                formula: "(NOW() - {{Start}}) / (1000*60)",
                label: "Elapsed Minutes",
                precision: 3,
                scale: 0,
                uiOnly: true
            },
            { 
                id: "ElapsedSeconds",
                accessible: true,
                calculated: true,
                createable: false,
                displaytype: "DOUBLE",
                editable: false,
                formula: "({{ElapsedMinutes}} - FLOOR({{ElapsedMinutes}}))*60",
                label: "Elapsed Seconds",
                precision: 2,
                scale: 0,
                uiOnly: true
            },
            { 
                id: "PrettyTime",
                accessible: true,
                calculated: true,
                createable: false,
                displaytype: "TEXT",
                editable: false,
                label: "Pretty Time",
                length: 255,
                uiOnly: true,
                formula: 'FLOOR({{ElapsedMinutes}})+":"+IF(LEN(ROUND({{ElapsedSeconds}})) = 1 ,'+
                    ' "0"+ROUND({{ElapsedSeconds}}) , ROUND({{ElapsedSeconds}}))'
            },
            { 
                id: "Color",
                accessible: true,
                calculated: true,
                createable: false,
                displaytype: "TEXT",
                editable: false,
                label: "Color",
                length: 255,
                uiOnly: true,
                formula: 'IF({{ElapsedMinutes}}>'+mintues3+', "'+color3+'",'+
                    ' IF({{ElapsedMinutes}}>'+minutes2+', "'+color2+'",'+
                    ' IF({{ElapsedMinutes}}>'+minutes1+', "'+color1+'","'+defaultColor+'")))'
            }
        ];

Hi Matt, sounds good that you could resolve it by yourself - thank you for taking the time to share your solution!