Documentation and Examples on Server-Side Scripting


#1

DreamFactory provides a server-side event system and server-side scripting with Javascript. In addition, you can set up security rules on the backend with lookup keys and server-side filters. Below are links to the docs and some blog posts which illustrate typical use cases.

Docs

Blogs


#2

Hi I have noticed all of the docs which used to be in Github are now gone. Is there any way to access these again?


#3

No, we made the 1.x documentation private because it was causing a lot of confusion now that DreamFactory 2.0 shipped. The latest documentation for DreamFactory 2.x is here http://wiki.dreamfactory.com/Main_Page.


#4

So no way to access? I am hoping they might hold the answer to what I am looking for. The 2.0 docs don’t.


#5

What’s the specific question? We’ll try to answer on this thread.


#6

Thanks Ben. My question is located here. I don’t know if I worded that well enough not to confuse but hopefully you will understand what I am trying to achieve. LINK HERE

But to simplify it a little say I have script the following event script wp_postmeta.get.post_process

if (event.response.record) {
    _.each(event.response.record, function (record, index, list) {
        if (record.meta_key == "_end_ts"){
            record.endseconds = record.meta_value;
        }
        if (record.meta_key == "_start_ts"){
            record.startseconds = record.meta_value;
        }
});
}

This table (wp_postmeta) is a child of the wp_posts table. So when I call a GET on wp_postmeta I get the modified data but when I call a GET on wp_posts and I include it’s relationships the wp_postmeta data (or wp_postmeta_by_id) is not modified. How can I have the above script do it’s work on the postmeta data whilst calling a GET on wp_posts?

Any clue you could give or direction you could point me would be hugely appreciated.

For example if I do a platform.api.get on the wp_postmeta table within another script how can I go about iterating over this data as we do in an event script with the _each function?

Thanks heaps.


Display items based on child data or modify data based on child data
#7

Same answer here will apply to 2.x as well. There is no direct way to apply child table scripts to parent table queries, reason being is because related queries don’t trigger an event for child tables. Currently you will have to write a script on the parent table and loop through each of the child records of each parent record.


#8

Thanks for your response. Do you have any idea how I might do that. I am unsure how to loop through those having tried things such as

var filter_data = {“filter”: “blahblah”};
var REQUEST = platform.api.get(“appname/wp_postmeta”,filter_data);

_.each(REQUEST.response.record, function (record, index, list) {

Do stuff here

});

But unfortunately no go. I am a bit of a noob unfortunately.

Any hints would be great. Thanks.

Jason.


#9

Ok thanks guys I solved this eventually.

if (event.response.record) {
    _.each(event.response.record, function (record, index, list) {
        _.each(record.wp_postmetas_by_post_id, function (record, index, list) {
        
            if (record.meta_key == "_end_ts"){
                record.endseconds = record.meta_value;
            }
            if (record.meta_key == "_start_ts"){
                record.startseconds = record.meta_value;
            }
        });    
    });
}

Jason.