Related param is ignored when trying to access api through event script

Hello all,

I’m trying to access api with related params through POST pre-process script,
but the related param is ignored, no related object is returned.

this is my request

var filter_params = {"related":[{"name":"voucher_redemption_by_voucher_id"}]};                   

var voucher = platform.api.get( "blu/_table/voucher", filter_params);
throw JSON.stringify(voucher);

i tried to set * to related to get all, but still none related object is returned.

to found a way around this, i added GET pre-process script to table voucher that should append a related param like below

event.request.payload.resource[0].related = [{"name":"voucher_redemption_by_voucher_id"}];

but this error is returned
> Cannot read property '0' of undefined

currently using:
Admin Application Version: 2.0.6
DreamFactory Version: 2.0.4

am i doing it wrong?

Thank you

Yahya

You can add it directly to the url like this.

var voucher = platform.api.get( "blu/_table/voucher?related=voucher_redemption_by_voucher_id");

Thank you todd, adding it directly to the url works.

one more question, how can i append related param in pre-process GET script, i tried using event.request.payload.resource[0].related, but it failed?

event.request.payload.resource[0].related = [{"name":"voucher_redemption_by_voucher_id"}];

error retuned

Cannot read property ‘0’ of undefined

thanks again

You can modify event.request.parameters like this.

event.request.parameters.related = "voucher_redemption_by_voucher_id";

But there’s a bug where modifications to the request object do not stick. It should be fixed by next week.