How to get the result in post-processor using javascript?

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Hi,

I have an integration service in which I need to check if a certain key is present or not. If the key is missing I would like to add that key with an empty value. Can this be achieved using js post-processor? If yes then how can I fetch the value of 'collection1' in post-processor?

Sample Response:

{ "opstatus": 0, "collection1": [ { "checkthiskey": "value1", "key2": "test1" }, { "key2": "test2" } ], "httpStatusCode": 200 }

Thanks and Regards

Hi,

to get the 'colelction1'

you can write a JS postProcessor

function myProcessor(){

var collection = result.getParamByName("colelction1");

}

myProcessor();

Thanks

Hi,

Thank you for your reply. I am getting null value in collection variable when I use the above code.

Regards

Hi,

If the above code doesn't work try below:

function test(){

var dataset = result.findDataset("collection1");

var records = dataset.getRecords();

for(var i=0; i<records.size(); i++){

if(records[i].getParam("checkthiskey") === null){

var paramTobeAdded = new com.konylabs.middleware.dataobject.Param();

paramTobeAdded.setName("checkthiskey");

paramTobeAdded.setValue("");

records[i].setParam(paramTobeAdded);

}

}

}

test();

Hi,

Thank you for your reply. The above solution is working as expected for me.

Regards

how can i get the result of post-processor in second service pre-processor ?

i am using orchestration services.

@Colin Wvtson​ please use code blocks for code snippets. It's the little button next to the emojis that looks like this: </>