# Is that possible to alter the request resource & parameters in pre-processing script?

**URL:** <https://community.dreamfactory.com/t/is-that-possible-to-alter-the-request-resource-parameters-in-pre-processing-script/3090>\
**Category:** Server-Side Scripting\
**Created:** [August 14, 2016, 6:15am UTC](https://community.dreamfactory.com/t/is-that-possible-to-alter-the-request-resource-parameters-in-pre-processing-script/3090 "2016-08-14T06:15:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lewis](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@lewis](https://community.dreamfactory.com/u/lewis)\
**Post date:** [August 14, 2016, 6:15am UTC](https://community.dreamfactory.com/t/is-that-possible-to-alter-the-request-resource-parameters-in-pre-processing-script/3090/1 "2016-08-14T06:15:10Z")

</div>

Hi all DF gurus,

I’m trying to alter the request resource & parameters in a PATCH request but seems out of luck. Please take a look at my code below:

> if (event.request.payload.fieldb) {  
> var filter = “(a = '” + event.resource + “') AND (b = " + event.request.payload.fieldb + “)”;  
> filter = encodeURIComponent(filter);  
> platform.api.get(”/url/\_table/mytable?fields=id&filter=" + filter, ‘’, function(body, res) {  
> var json = JSON.parse(body);  
> var newid = json.resource[0].id;  
> event.resource = newid;  
> event.request.parameters = {};  
> console.log(“request altered”);  
> })  
> }  
> console.log(event.resource);  
> console.log(event.request.payload);  
> throw new Error(“dev - debug breakpoint”);

Client fire a PATCH request to “/url/\_table/mytable?id\_field=fieldc”. In ideal world, if fieldb exists in the request.payload, the script should fire a GET request and overwrite the event.resource, and then remove the parameters (id\_field=fieldc), therefore the console.log at the bottom should show the altered resource & payload, but then, this script seems running in asynchronous mode, the 2x console.log at the bottom show first and only then console.log(“event altered”) show.

I’m wondering is there any asynchronous/sync switch that I can use in this case? or there is a more proper way to achieve this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Vinod\_Hum](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@Vinod\_Hum](https://community.dreamfactory.com/u/Vinod_Hum)\
**Post date:** [August 15, 2016, 1:57am UTC](https://community.dreamfactory.com/t/is-that-possible-to-alter-the-request-resource-parameters-in-pre-processing-script/3090/2 "2016-08-15T01:57:26Z")

</div>

were you able to figure out how to update request on pre process ?  
I am also looking for same solution where I want to update request from images/20.jpg to images/unauthorized.png

thanx

---

<div class="post-metadata">

**Author:** ![Vinod\_Hum](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@Vinod\_Hum](https://community.dreamfactory.com/u/Vinod_Hum)\
**Post date:** [August 15, 2016, 2:23am UTC](https://community.dreamfactory.com/t/is-that-possible-to-alter-the-request-resource-parameters-in-pre-processing-script/3090/3 "2016-08-15T02:23:43Z")

</div>

ok may be we could just redirect.  
do you know how to redirect the request ?
