Page 1 of 1

Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Fri Nov 22, 2013 12:42 am
by Patrick Kelly

I am creating a page that invokes the Geolocation service that is going to be a template for a variety of other pages that I will make. I have JavaScript code in that page that invokes the service within an ifelse statement. The problem is that, when I duplicate the page, the name of the service changes appending a "_clone_1" to the end. Is there any way that I can duplicate the page without having to go into the code every time to change the service name?


Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Fri Nov 22, 2013 1:34 am
by Alena Prykhodko

Hi Patrick,

You can execute service with the following code:
preservice_name.execute({});/pre

In this case when you duplicate the page service_name won't be changed.


Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Fri Nov 22, 2013 4:06 am
by Patrick Kelly

I think you misunderstood the problem. I am using that code in the ifelse statement. My problem is that when a page is duplicated, the service name ITSELF is changed. As in, when you select the data tab, under the column "Name", "serviceName" becomes "serviceName_clone_1", while the code still calls "serviceName". Because the service "serviceName" does not exist in the duplicate page (only serviceName_clone_1), nothing happens.

I was curious is there was a way that I could either have the code update automatically (as in "serviceName.execute({});" becomes "serviceName_clone_1.execute({});") or find some other way that I can duplicate the page and invoke the correct service without going back into the code and changing it.

It's not a huge deal, it's just that there are a lot of pages and a lot of data input, so I am passing off some of the input work to people who do not know how to program and I don't want to risk them screwing something up by entering the code to change the name every time. Can you help out?


Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Fri Nov 22, 2013 4:53 am
by maxkatz

There is no such option right now, you would need to make the changes in the code.


Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Sat Nov 23, 2013 3:31 am
by Patrick Kelly

For those interested, I have developed a work-around solution. Making an event that says "componentNameClickInvoke serviceserviceName" automatically updates when the page is duplicated and it appends a "clone#" to the end of the original service name. My problem was that I needed to invoke the service within JavaScript code (I needed to do a check using an if else statement before invoking the service) and that, of course, does not auto-update, making the code useless unless I go into the code for every duplication and append a "clone#" to the end every time, manually. So I began to guess and check using the test function and this is what I came up with:

Set up a component, any component, whether it be a button, a toggle, or even an input field. Name it what you please and/or add any text you want, just uncheck the "visible" checkbox in the end, so that users don't see what is going on. Open the "Events" tab and make a new event: componentNameVirtual clickInvoke serviceserviceName.

Then, instead of invoking the service in code by using the execute command as you would normally:

codeserviceName.execute({});/code

Use the ".trigger()" event handler (I couldn't get ".click()" to work) to virtually click the component:

code Appery("componentName").trigger("click");/code

This will virtually click the component, triggering the event that you set up to invoke the service. If you are using the page as a template or ever need to duplicate the page for any reason, when the service name changes in the "Data" tab, the service name will also change in the event. making the page function without needing to enter the code every time!


Is there any way to invoke a service in JavaScript and not need to change the code when you duplicate the page?

Posted: Sat Nov 23, 2013 3:37 am
by maxkatz

Thanks for sharing.