How to set a column based on the value chosen from a dataset on another column

Assuming I have a column named project_media_type which is populated with a random value from this dataset:

  • image
  • animated_gif_player
  • embedded_video
  • embedded_iframe
  • embedded_code_snippet
  • image_gallery
  • etc…

Next I also have these 2 columns code and code_embedded

I want to do this if possibble:

  • Make both code and code_embedded columns be null if project_media_type does not have a value of embedded_code_snippet

next I also want to make column code null if project_media_type does have a value of embedded_code_snippet however embedded_code_snippet is a JSON field which has another hidden column embedded_code_snippet.code_source

Now embedded_code_snippet.code_source picks a value from another dataset which has options

  • codepen
  • jsfiddle
  • jsbin
  • gist
  • local

so when embedded_code_snippet.code_source picks a value of local I would then like to populate the column code with random code/text data

I know this sounds confusing but it is simple when you think about it. I am just not sure if it is too complex for Mockaroo?


More simple view if a do a if/else block…

if(  project_media_type === 'embedded_code_snippet' ){

    // column embedded_code_snippet is a JSON data type
    // embedded_code_snippet.code_source is populated from a dataset

    if( embedded_code_snippet.code_source === 'local' ){
        // make column code = random code/text
    }else{
        // make column code = null
    }
}else{
    // make column code = null
    // make column embedded_code_snippet = null
}

Have you looked at the Formula data type? It allows you to specify custom logic and inter-column dependencies like this using ruby syntax.

I see now the Ruby part. I had seen the demo for formula but thought it just had the shown functions now I see it can use custom Ruby code too that will help.

My next obstacle is figuring out if it is possibble to change another columns data type on the fly based on my other column value. The RUby code can determine the values but it might not be possibble to change a columns data type


UPDATE:

I just saw your username, so you would likely know the answer to this question =) thanks for the amazing site it is 1 of a kind

In addition to the formula datatype, Mockaroo also allows you to alter the output of any column with a formula by clicking the f(x) button. Whatever is returned from that formula is the generated value. You can access the current value of the column using the this keyword.