Custom action output variables show up empty

Brian Hofmeiste
Kilo Guru

I have a custom action that runs a rest script. Part of the script retrieves a response body on execution.  That response body shows up correctly if I place it inside gs.info but if I assign it to an output variable the variable is always empty.  Anyone experience this? I’ve tried casting the response body to string.  I’ve tried parsing it.  No matter what I do - the output variable is always empty.  

1 ACCEPTED SOLUTION

You should be using the name of the output variable.

Still curious why not use the OOB rest steps & JSON Parser as well and potentially even the Okta spoke since it seems like you're doing an Okta integration?

View solution in original post

8 REPLIES 8

Tushar
Kilo Sage
Kilo Sage

Try to log or print the response body using gs.info to verify that it indeed contains the expected content. To verify that the issue is not with the retrieval of the response itself.

Check the definition and configuration of the output variable in your custom action. Verify that it has the correct data type (such as String) and it is properly mapped to the script variable where you want to store the response body.

Also the REST API you're calling, the response body may be in a specific format, such as JSON or XML. Double check that you are handling the response body appropriately based on its format. If it is JSON, you may need to parse it using JSON.parse() to access the data.

 

Thanks.

-O-
Kilo Patron
Kilo Patron

Can you share the (anonymized) code?

Mike Rakvica1
Tera Guru

If you're already doing a custom action why don't you use a rest step paired with a JSON parser step instead of the RestMessage v2 within a script?

 

Also without seeing how you're trying to assign the output it will be very hard to troubleshoot why it's not producing the results your expecting? One thing to check is to make sure you're assigning the script step output from within the script, and then the action output with the value of the variable from your script step.

Here is the script step of the action:

 

(function execute(inputs, outputs) {

  try { 
 var r = new sn_ws.RESTMessageV2('Okta', 'Create User');
 r.setStringParameterNoEscape('lastName', inputs.lastName);
 r.setStringParameterNoEscape('password', inputs.password);
 r.setStringParameterNoEscape('email', inputs.email);
 r.setStringParameterNoEscape('firstName', inputs.firstName);
 r.setStringParameterNoEscape('login', inputs.login);
 var response = r.execute();
 outputs.httpStatus = response.getStatusCode();
 outputs.responseBody = response.getBody();
}
catch(ex) {
 var message = ex.message;
}
  
})(inputs, outputs);

And here is the output variables

BrianHofmeiste_0-1689463468852.png

And now that I'm posting this I think I see the problem.... My code uses the capitalization in the label.  Is the label what I should be using in the code?  OR should I be using the name which doesnt have the capitalization?