So the error that I came across is due to the featureset not likeing alphnumeric field names for integers or strings.
To bypass this; I created a list of alphabetical letters and then indexed those for the field names which seemed to bypass that issue.
function GetPctColor(P){
var Color = When(
P >= 0 && P < 5,'#d01111',
P >= 5 && P < 10,'#cc2211',
P >= 10 && P < 15,'#c83311',
P >= 15 && P < 20,'#c34211',
P >= 20 && P < 25,'#bf5112',
P >= 25 && P < 30,'#bb5f12',
P >= 30 && P < 35,'#b76c12',
P >= 35 && P < 40,'#b37912',
P >= 40 && P < 45,'#af8512',
P >= 45 && P < 50,'#ab9012',
P >= 50 && P < 55,'#a79a12',
P >= 55 && P < 60,'#a2a312',
P >= 60 && P < 65,'#919f12',
P >= 65 && P < 70,'#819b12',
P >= 70 && P < 75,'#719712',
P >= 75 && P < 80,'#639312',
P >= 80 && P < 85,'#558f11',
P >= 85 && P < 90,'#478b11',
P >= 90 && P < 95,'#3b8711',
'#2f8311'
)
return Color
}
var Alph = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V']
var fields = []
var V = {}
var counter = 0
for( var i=5; i<= 95; i=i+5 ){
if( i%5 == 0 ){
var l = Alph[ counter ]
var f = {'name':l, 'type':'esriFieldTypeSmallInteger'}
Push( fields , f )
V[ l ] = i
var n = {'name':'c'+Text(i), 'type':'esriFieldTypeString', Length:7}
Push( fields , n )
V[ 'c'+Text(i) ] = GetPctColor(i)
counter++
}
}
var Ramp = {
'fields': fields,
'geometryType':'',
'features' : [{ attributes : V }]
}
Ramp = FeatureSet(Text(Ramp))
return Ramp