Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

Read and change service settings in Javascript

Hi. I have a settings service defines for the URL that I'm using to do my rest calls. That is working fine. Can I change that URL in javascript prior to the mapping ? I see there is a "before send" event that can process javascript. I'm guessing I can put it in there but how do I refer to the settings ? I've tried settings.data and settings.url but the console log says settings is undefined. Whats the object I need to refer to ?

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

Read and change service settings in Javascript

OK. Eventually worked out something. Not sure if its the best method but seems to work.

If you use javascript in the "before send" event you can find your settings in "this.service.__requestOptions.serviceSettings". Just add .YourParameterName and you'll have it.

I do this prior to the mappings and can dynamically change the value of what is being mapped in the requests via say a {URL}. You'd find that in this.service.__requestOptions.serviceSettings.URL

I'm doing this so I can have a path going to a "live" or production environment or to or a test environment thus keeping them completely separate. Can then also use for training purposes as well as development. I have a page on the log on screen that you can go to where you can toggle between either environment (at this stage defaults to and reverts back to production). If there is an easier way I'm open to suggestions

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Read and change service settings in Javascript

Hi Bob,

We recommend that you specify this URL value in service settings:code{url}/code.

Then add a request parameter 'url'. Appery.io will automatically replace code{url}/code with a value you pass in the parameter 'url'. For example use Before send mapping.

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

Read and change service settings in Javascript

I didn't know about the {url} trick but was being lazy but will do as you suggest and do it properly

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Read and change service settings in Javascript

Hi Bob,

Yes you can use it where you need.

Here is details about about this feature: http://devcenter.appery.io/documentat...

Regards.

Return to “Issues”