Trying to run node java script

Hi Team,

I am trying to execute a script wherein the script should check whether the api response is completed or not , if not then it should continue to check & once its completed it should come out after while loop.

Script i wrote

context.code=false;
var codestatus= context.getworkitemStatus.response.body.status;
while(context.code === false){
codestatus= context.getworkitemStatus.response.body.status;
if(codestatus === “COMPLETED”){
context.code=true;
}
else{
context.code=false;
}
}

But its not working.

Please anybody can guide me

@aditya.singhania
When you are in a script node, assuming that it is ‘after’ the service node, the bot will focus only on the script node. The response from the service node will be stored in the context and the service node will not be revisited unless you loop the bot flow with some checks.

So, in your case, the service node has been executed already, the response would have been stored in the context. If there is an error in execution, the bot will use task execution failure. The script that you have written is not a valid code and it may not be expected to keep checking the status of the service API call.

Please know that the service node has a timeout of a max of 20 seconds. If you are expecting more delay in response, you may need to work on the BotKit with a webhook node. The below post may be useful if you are trying to asynchronously get a particular status.