# How to manipulate data on the fly with server side scripts

**URL:** <https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930>\
**Category:** Server-Side Scripting\
**Created:** [March 17, 2015, 4:54pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930 "2015-03-17T16:54:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![whalan84](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@whalan84](https://community.dreamfactory.com/u/whalan84)\
**Post date:** [March 17, 2015, 4:54pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/1 "2015-03-17T16:54:11Z")

</div>

Hi, I am new to Dreamfactory. I am trying to modify a field on all of the records of a REST call using get.post\_process event script. I am struggling to get my head around it a little. I have manipulated some examples I have found online but my attempts don’t seem to be the correct method.

Here is an example of what I have tried.

```
 if (event.request.body) {
_.each(event.request.body, function (record) {
    record.name = 'New Name Here';
});
} 

```

If anybody could give me any assistance or lead me in the right direction I would be very appreciative.

Thank you.

---

<div class="post-metadata">

**Author:** ![benbusse](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/benbusse/32/4_2.png) [@benbusse](https://community.dreamfactory.com/u/benbusse)\
**Post date:** [March 17, 2015, 5:27pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/2 "2015-03-17T17:27:16Z")

</div>

Try this

```
 if (event.request.body.record) {
_.each(event.request.body.record, function (record) {
    record.name = 'New Name Here';
});
}
```

---

<div class="post-metadata">

**Author:** ![toddappleton](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/toddappleton/32/159_2.png) [@toddappleton](https://community.dreamfactory.com/u/toddappleton)\
**Post date:** [March 17, 2015, 6:08pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/3 "2015-03-17T18:08:43Z")

</div>

Also have a few examples on the wiki.

[https://github.com/dreamfactorysoftware/dsp-core/wiki/Server-Side-Scripting](https://github.com/dreamfactorysoftware/dsp-core/wiki/Server-Side-Scripting)

---

<div class="post-metadata">

**Author:** ![whalan84](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@whalan84](https://community.dreamfactory.com/u/whalan84)\
**Post date:** [March 18, 2015, 12:01am UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/4 "2015-03-18T00:01:32Z")

</div>

Thanks for the help. Unfortunately this still doesn’t seem to be working for me. Could it be a conflict with the fact my data is a mySQL database which I am accessing from another remote server? I can get custom scripts to work but not the event scripts. I don’t see any effect on the data from API docs nor test\_rest.html.

I am using a custom script to access ‘eventmaster’ table and only display future items (no items who’s ‘startdate’ is 48 hours older than current date).

```
function getDate()
{
var dNow = new Date();
var theDate = (dNow.getTime()/1000);
return parseInt(theDate);
}
function initialise()
{
var queryString = getDate()+172800;
var filter_data = {"filter": "startdate>'" +queryString+ "'"};
var request = platform.api.get("buzzn/eventmaster",filter_data);
return request;
}
result = initialise();
return result;

```

Is there some way I can maybe do the manipulation as a part of this custom script instead?

---

<div class="post-metadata">

**Author:** ![whalan84](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@whalan84](https://community.dreamfactory.com/u/whalan84)\
**Post date:** [March 18, 2015, 8:24am UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/5 "2015-03-18T08:24:43Z")

</div>

When I create an error with a script it does affect my call so it seems the script is being called on the event yet when I use the below script the ‘name’ field’s data remains unchanged. What could be the reason for this?

```
if (event.request.body.record) {
_.each(event.request.body.record, function (record) {
record.name = 'New Name Here';
});
}
```

---

<div class="post-metadata">

**Author:** ![whalan84](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@whalan84](https://community.dreamfactory.com/u/whalan84)\
**Post date:** [March 20, 2015, 6:18am UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/6 "2015-03-20T06:18:09Z")

</div>

The correct script for this to work was…

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

---

<div class="post-metadata">

**Author:** ![toddappleton](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/toddappleton/32/159_2.png) [@toddappleton](https://community.dreamfactory.com/u/toddappleton)\
**Post date:** [March 20, 2015, 12:42pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/7 "2015-03-20T12:42:22Z")

</div>

If you want to change the value in the database, it needs to be done in the pre\_process script like Ben’s example. If you just want to change the value returned to the client but not the value in the db then do it in the post\_process script like you showed.

---

<div class="post-metadata">

**Author:** ![whalan84](https://avatars.discourse-cdn.com/v4/letter/w/ebca7d/32.png) [@whalan84](https://community.dreamfactory.com/u/whalan84)\
**Post date:** [March 20, 2015, 3:44pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/8 "2015-03-20T15:44:06Z")

</div>

Ok, thank you. Perhaps I should have been more specific in my initial question. I dumbed the script down a little. What I really intended to do was pass a description value off to another JS function to turn URLs in to clickable hyperlinks and then change the description to this new modified text on the fly without changing the database. All is working great now.

---

<div class="post-metadata">

**Author:** ![damion](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/damion/32/1074_2.png) [@damion](https://community.dreamfactory.com/u/damion)\
**Post date:** [June 11, 2019, 12:54pm UTC](https://community.dreamfactory.com/t/how-to-manipulate-data-on-the-fly-with-server-side-scripts/930/9 "2019-06-11T12:54:25Z")

</div>

Please Reply admins. Open an issue. Do something.
