RUN SCRIPT

shabbir9
Tera Contributor

HI 

 

in workflow run script activity iam creating POST request to other application i am getting response 200

i need to move to next activity in workflow based on HTTP Response if response is 200 move to next activity in workflow if response is not equal to 200 i need to create a task below are the scripts i am using 1.run script in workflow to capture http response 2,"if activity "script to move forward next step if response is 200 not equal 200 need to create a task can anyone help me in scripts

script 1:

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

workflow.scratchpad.response = httpStatus;

 

script 2(if activity script)

 

function ifScript() {
var code = workflow.scratchpad.response;
gs.log('code is '+code);
if (code == 200) {
return 'yes';
}
else{
return 'no';
}
}

 

Kindly reply if further clarity on this question

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

Is this not working correctly?  If not, what is in the log for 'code'?  If it's not what is expected, log httpStatus and/or workflow.scratchpad.response in the previous script.  If the log for 'code' is showing the expected value, try changing your if statement to  

 

if (code == '200') {

 

since scratchpad variables are stored as a string.  Also make sure your if activity script starts with a line to call the function

answer = ifScript();

View solution in original post

David Whaley
Mega Sage

This should work as long as you are getting 200 as a result.

answer = ifScript();
function ifScript() {
    if (code == '200') {
        return 'yes';
    }
    return 'no';
}

I have used response.getStatusCode() which I think returns '200 OK'

 

David

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Is this not working correctly?  If not, what is in the log for 'code'?  If it's not what is expected, log httpStatus and/or workflow.scratchpad.response in the previous script.  If the log for 'code' is showing the expected value, try changing your if statement to  

 

if (code == '200') {

 

since scratchpad variables are stored as a string.  Also make sure your if activity script starts with a line to call the function

answer = ifScript();

David Whaley
Mega Sage

This should work as long as you are getting 200 as a result.

answer = ifScript();
function ifScript() {
    if (code == '200') {
        return 'yes';
    }
    return 'no';
}

I have used response.getStatusCode() which I think returns '200 OK'

 

David