How to apply ignored to false in postResponseMap function

I have the written the below postResponseMap hook function to remove certain records from array which doesn't qualify the condition.

function postResponseMap (options) {
var newPostResponseMapData = [];
var j=0
for (var i=0 ; i< options.postResponseMapData.length ; i++){
var offeringDetails = options.postResponseMapData[i].offeringDetails[0]
offeringDetails.resources=offeringDetails.resources[1]
if(offeringDetails.resources.length>0 && offeringDetails.vleinfoDetail.guestAttendUrl==null && offeringDetails.vleinfoDetail.vleProvider!=null && offeringDetails.vleinfoDetail.vleProvider.displayName=='Non Integrated VLE Provider'){
newPostResponseMapData[j] = options.postResponseMapData[i];
j=j+1;
} else{
delete options.postResponseMapData[i]
}
}
return newPostResponseMapData
}

When the flow is executed, I am receiving the error "Extension result doesn't contain the same number of elements as the request object." due to truncation of records.

Let me know how to skip/remove certain records in postResponseMap hook/function without getting errors.

Note: There was no proper example for postResponseMap hook/function in help center.

2

Comments

7 comments
Date Votes
  • Kiruba Devarajan,

    I encourage others who might have gotten around this error to share their tips, but as you're probably aware the scope of this question is best treated with consulting help: 

    If you would like to work with someone more closely to help you through your custom flows, you could consider consulting hours. Also, we have the integrator.io Office Hours program where you can call in and get a free consultation. 

    Also, are you familiar with a recently released feature, Debug your scripts in integrator.io? You can print the value of your data arrays or indices, above, to the script’s execution log at any point – before, during, or after the for() loop. 

    0
  • Hi Kiruba,

    We came across the same issue today. You might've already figured it out but just in case anyone else sees or comes across this, it seems like returning options.postResponseDataMap was what we needed to do. So we just modified each of the options.postResponseDataMap's array items (instead of creating a new array) with the data we needed and returned that same exact object back, i.e do this:

    return options.postResponseMapData;

    I hope this helps - good luck!

    1
  • I have been running in the same issue, but I believe when you build the flow, make sure in postResponseDataMap you will have the same details as your request object.

    Also, can you share your details if you solve the issue?

    0
  • Akber, you could check this updated article.

    0
  • Anitha Abraham I went looking a the linked article but I don't see why you posted that link. It doesn't describe the `postResponseMap` function, it parameters or other requirements. Maybe I'm misunderstanding something. It would be nice if that article DID describe the function though because I'm here on the community pages trying to learn about how to use this function.

    0
  • Interesting. The UI process to create a post response map function is odd. It seems you need to create the script record in the resource panel first, then come back and click the script icon on the export. Then you select the script file you created earlier. There is also a button to insert the function stub, which is nice because these are the docs I was wanting. Anyway, thought I'd share in case anyone else is struggling to create a postResponseMap script.

    0
  • Here's the correct link for the article. 


    https://docs.celigo.com/hc/en-us/articles/5926315530139-Import-hooks#postResponseMapHook

    The function needs to return the responseData array provided by options.responseData. The length of the responseData array must remain unchanged. Elements within the responseData array can be modified to enhance error messages, modify the complete _json response data, etc...

     

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post