cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Call service with service name stored as variable

azoorob3
13-Aquamarine

Call service with service name stored as variable

Hi Everyone,

 

I'm trying to call a service whose name will be stored in a variable. For example, here's how I would normally call the service GetJobOrder:

 

 

let params = {UID: '7'};
const result = me.GetJobOrder(params);

 

 

However, I want to be able to execute a service if the service name is stored in a variable rather than explicitly typed out. For example, this is what I've tried:

 

let scriptName = 'GetJobOrder';
let params = {UID: '7'};

const result = me.svc[scriptName](params);

 

 

I wasn't able to get this to work as shown below: 

 

1.png

 

I tried various ways to try to call the service but none were successful: 

 

2.png

 

Does anyone know if this is possible? How can I call a service when the service name is stored in a variable, rather than explicitly specifying the service name?

 

Thanks for your help.


Andrew

ACCEPTED SOLUTION

Accepted Solutions
nmutter
14-Alexandrite
(To:azoorob3)

var scriptName = 'GetJobOrder';
var params = {UID: '7'};

var result = me[scriptName](params);

Like this You almost got it!

View solution in original post

2 REPLIES 2
nmutter
14-Alexandrite
(To:azoorob3)

var scriptName = 'GetJobOrder';
var params = {UID: '7'};

var result = me[scriptName](params);

Like this You almost got it!

azoorob3
13-Aquamarine
(To:nmutter)

Perfect, that did the trick! Thanks a bunch for your help, much appreciated. 

Announcements


Top Tags