i use datasets all the time to move queries out of...
# sdf
s
i use datasets all the time to move queries out of code and i never create workbooks for them (unless there's some specific need). i can't be the only one who thinks this is nonsense:
An error occurred during custom object validation. (custdataset_rollover_to_carve)
Details: The custdataset_rollover_to_carve dataset object must have at least one workbook object referencing it.
File: ~/Objects/custdataset_rollover_to_carve.xml
n
Unfortunately that's the only way I know as well so far 😔
s
i toyed with using an initialization function. you can dump the finalized dataset to code, put it in a function that gets called by the script if the dataset isn't yet defined. it worked, but it's really not great. i'd opportunistically remove the init function on the next change for the script too. i was playing around with a way to automatically generate the initialization function, but then i realized i should just give in and create a workbook. but sometime i forget and then i'm left here, just shaking my head.
n
s
yeah, it's not super complicated to recreate a dataset, but it's annoying. i used something like this when i was using the 'initialization function' approach. dump the dataset to json, then stringify it. use it as the input to something like this. it worked for my datasets at the time. it would probably still work. 🤣
Copy code
const jsonDataset = JSON.parse(<that value>)

jsonDataset.columns = jsonDataset.columns.map( c => columnReconstitutor(c))
jsonDataset.condition = conditionReconstitutor(jsonDataset.condition) 

dataset.create(jsonDataset).save({name: jsonDataset.name, id: jsonDataset.id})
 
function conditionReconstitutor(condition, createConditionFunc = dataset.createCondition, createColumnFunc = dataset.createColumn){
  condition.children = condition.children ? condition.children.map( kid => conditionReconstitutor(kid)) : null
  condition.column = condition.column ? columnReconstitutor(condition.column) : null
  return createConditionFunc(condition)
}

function columnReconstitutor(column, createColumnFunc = dataset.createColumn,){
  column.join = column.join ? joinReconstitutor(column.join) : null
  return createColumnFunc(column)
}

function joinReconstitutor(join, createJoinFunc = dataset.createJoin){
    join.join = join.join ?  joinReconstitutor(join.join) : null
    return createJoinFunc(join)
}