Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Empty Data Output in Data Stream Action

Beata I_owiecka
Kilo Guru

Hi everyone,

 

I've created a Data Stream Action that gets paginated records from REST endpoint.

Or actually the one that SHOULD get this records, but it doesn't.

What can I do to make this work?

 

Data Output (in execution details after I test the action):

data_output.png

 

Action Outline:

action_outline.png

Execution details when I test, show that REST Step returns a proper response body.

response_body.png

Splitter didn't throw any errors, it should be fine.

In Parsing, Script Parser step, I use script:

 

 

(function parse(inputs, outputs) { 
    var glacier_rec = JSON.parse(inputs.sourceItem); 
    
    outputs.targetObject.id = glacier_rec.glacier_id; 
    outputs.targetObject.name = glacier_rec.name; 
    outputs.targetObject.country = glacier_rec.country;
    outputs.targetObject.latitude = glacier_rec.latitude; 
    outputs.targetObject.longitude = glacier_rec.longitude;
})(inputs, outputs);

 

 

 

And the Output is:

output_edit.pngaction_output.png

 

Thanks in advance!

1 ACCEPTED SOLUTION

Beata I_owiecka
Kilo Guru

It's very sad to say this.. but this solved the problem:

(I just stripped some spaces in Parsing Script 😑)

(function parse(inputs, outputs) {
    var glacier_rec = JSON.parse(inputs.sourceItem); 
    
    outputs.targetObject.ID=glacier_rec.glacier_id; 
    outputs.targetObject.name=glacier_rec.name; 
    outputs.targetObject.country=glacier_rec.country;
    outputs.targetObject.latitude=glacier_rec.latitude; 
    outputs.targetObject.longitude=glacier_rec.longitude;

})(inputs, outputs);

action_output_works.png

 

The hint came from here: https://www.servicenow.com/docs/bundle/xanadu-integrate-applications/page/administer/integrationhub/...

 

Exactly this made me think about stripping the spaces: (btw - in xml parsing script example the spaces are not stripped..)

data-stream-docs.png

 

Finally it works!

Have a great day! 🙂

View solution in original post

4 REPLIES 4

Vishal Jaswal
Giga Sage
Giga Sage

Hello @Beata I_owiecka 

Try this:

(function parse(inputs, outputs) {
   var glacier_rec = JSON.parse(inputs.sourceItem);
   // Ensure targetObject is defined
   outputs.targetObject = {};
outputs.targetObject.id = glacier_rec.glacier_id;
   outputs.targetObject.name = glacier_rec.name;
   outputs.targetObject.country = glacier_rec.country;
   outputs.targetObject.latitude = glacier_rec.latitude;
   outputs.targetObject.longitude = glacier_rec.longitude;
})(inputs, outputs);

Hope that helps!

Medi C
Giga Sage
Giga Sage

Hi @Beata I_owiecka,

 

Does your REST API returns always 1 object?

if so please adjust your Parsing function as:

(function parse(inputs, outputs) { 
    var glacier_rec = JSON.parse(RESPONS_BODY_FROM_REST_STEP); 
    
    outputs.targetObject.id = glacier_rec.result.glaciers[0].glacier_id; 
    outputs.targetObject.name = glacier_rec.result.glaciers[0].name; 
    outputs.targetObject.country = glacier_rec.result.glaciers[0].country;
    outputs.targetObject.latitude = glacier_rec.result.glaciers[0].latitude; 
    outputs.targetObject.longitude = glacier_rec.result.glaciers[0].longitude;
})(inputs, outputs);

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Beata I_owiecka
Kilo Guru

Hi @Medi C, @Vishal Jaswal,

 

Before the Parsing script I added Splitter step with Item Path: $.result.glaciers

So I think the result is one glacier at a time and logs are comfinminig that.

I added two logs at the end of a script:

...
    outputs.targetObject.longitude = glacier_rec.longitude;

    gs.info("* ❤️ glacier_rec.name: " + glacier_rec.name);
    gs.info("* ❤️ outputs.targetObject.name: " + outputs.targetObject.name);
})(inputs, outputs);

 

And I got result:

log-data-stream.png

 

So I'm wondering why output.targetObject is not passing the data to the outputs. Maybe the problem is in my Action Output configuration?

Beata I_owiecka
Kilo Guru

It's very sad to say this.. but this solved the problem:

(I just stripped some spaces in Parsing Script 😑)

(function parse(inputs, outputs) {
    var glacier_rec = JSON.parse(inputs.sourceItem); 
    
    outputs.targetObject.ID=glacier_rec.glacier_id; 
    outputs.targetObject.name=glacier_rec.name; 
    outputs.targetObject.country=glacier_rec.country;
    outputs.targetObject.latitude=glacier_rec.latitude; 
    outputs.targetObject.longitude=glacier_rec.longitude;

})(inputs, outputs);

action_output_works.png

 

The hint came from here: https://www.servicenow.com/docs/bundle/xanadu-integrate-applications/page/administer/integrationhub/...

 

Exactly this made me think about stripping the spaces: (btw - in xml parsing script example the spaces are not stripped..)

data-stream-docs.png

 

Finally it works!

Have a great day! 🙂