How to manipulate child data using server side scripting

I currently have the following script which manipulates the eventmaster_by_eventid field.

if (event.response.record) {
_.each(event.response.record, function (record, index, list) {
record.eventmaster_by_eventid = 'New Name Here';
});
}

This works, but I am trying to manipulate a child field of eventmaster_by_eventid (called status). I am only new to this stuff and just trying to get my head around it but I was hoping I could do this somehow such as below but I am obviously off track a little.

if (event.response.record) {
_.each(event.response.record, function (record, index, list) {
record.eventmaster_by_eventid.status = 'New Name Here';
});
}

Can anybody give me any direction with this… really need to sort it out quite urgently. Any help is appreciated. Thanks.

I recommend you check this thread where another user has a very similar question.

In the foreach loop you can var_dump the record. Then you can check the log file in dsp-core/log to see what objects and fields are available, and if there were any errors.

if (event.response.record) {
     _.each(event.response.record, function (record, index, list) {
         var_dump(record);
         record.eventmaster_by_eventid.status = 'New Name Here';
     });
 }

You have to make a database call using platform.api.put() to write the changes. I don’t see that anywhere in your script. See this wiki page for examples.

https://github.com/dreamfactorysoftware/dsp-core/wiki/API-Access-via-Scripts

Hi Todd, the fields all seem to be there when using var_dump. I am just still unsure how to access them.

I should mention this is an event get.post_process script… trying to access the values so I can pass the values to another script without modifying the database at all.

Thanks Todd and Jeffrey for your help. I appreciate it a lot. It turned out

if (event.response.record) {
_.each(event.response.record, function (record, index, list) {
record.eventmaster_by_eventid.status = 'New Name Here';
});
}

actually does work… I am unsure what I was doing to think that that wasn’t working but it infact does. I am loving DreamFactory. Thanks again.

1 Like