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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Service Help

Carl985
12-Amethyst

Service Help

Hi I am still trying to learn java whilst trying to develop my thingworx app and I am trying to write a service to define the production shifts depending on if a boolean property is true and and shift has been selected from a drop drown (string) but services keeps failing saying specific shift (string) is not defined see image. Do I need to do a function call to return the string?

Carl985_0-1640111279360.png

 

ACCEPTED SOLUTION

Accepted Solutions
Carl985
12-Amethyst
(To:Carl985)

Fixed it now needed 

 

const d = new Date();
let time = d.getHours();

View solution in original post

7 REPLIES 7

Hello @Carl985 , 

 

Can you please share the error you are getting?

 

Regards

Bhawna

Carl985
12-Amethyst
(To:bchaudhary)

Hi Bhawna

 

Please see below

Carl985_0-1640185012695.png

Regards

Carl

@Carl985 

 

I reviewed your code and it seems fine. I also did a quick test and I am able to execute a similar service on my local instance. 

Please enable debug logging in script logs and after replicating the issue again provide us the Script and ScriptError logs to check the exact cause.

 

Regards,

Sachin Sharma

 

Hi Sachin,

 

Code is now working seems I did not put the Mornings like this 'Mornings' and I now do not get the error but can you tell me why it always evaluates to the last else statement even if the conditions for the else if are met ?

@Carl985 

 

I used below code and when else if condition is true it is updating thing property prop1 value to 2.

There are two inputs machinerunselect (boolean) and productionshifts (string)

 

let runselect = machinerunselect;
let shifts = productionshifts;

if(runselect ===true && shifts === "Mornings" ){
(me.prop1 = 1);}
else if(runselect ===true && shifts === "Afternoons" ){
(me.prop1 = 2);}
else(me.prop1 = 5);

 

For testing purpose remove the time condition from first else if statement and execute the service again, pass the following inputs productionshifts = Nights and machinerunselect = true

Check whether ShiftScheduleUID updated to 3 or not.

 

Regards,

Sachin Sharma

Hi Sachin,

 

Thank you it works now but why will it not work with the time variable? If I run the time script on the console it returns a value so why does it evaluate to false in my script on thingworx? 

Carl985_0-1641298364080.png

 

Carl985
12-Amethyst
(To:Carl985)

Fixed it now needed 

 

const d = new Date();
let time = d.getHours();

Announcements


Top Tags