Change null value into 0 with data action flow variable initial value collection

Hi All,

I am struggling with null values that come from a client API. The raw result is

"errors.code": [
"backend_error"
],
"errors.message": [
"BOSS"
],
"results.address.street_name": [
null
],
"results.address.zip_code": [
null
],
"results.address.country": [
null
],
"results.address.city": [
null
],
"results.address.house_number": [
null
],
"results.contact_phone_number": [
null
],
"results.date_updated": [
null

So the data action breaks if it sees null , at first I thought the solution was "set initial value to 0" from a flow variable and it worked too. Later on it didn't anymore. What goes wrong here? please any help is welcome :slight_smile:
image

Hi Jerry,

Could you include the results of the "Execute" step in test mode, along with your response configuration and output contract?

Also, when you say that the data action breaks, do you mean that it is taking the failure path in architect?

--Jason

Hi Jason,

here is the raw result :slight_smile: {
"errors.code": [
"backend_error"
],
"errors.message": [
"BOSS"
],
"results.address.street_name": [
null
],
"results.address.zip_code": [
null
],
"results.address.country": [
null
],
"results.address.city": [
null
],
"results.address.house_number": [
null
],
"results.contact_phone_number": [
null
],
"results.date_updated": [
null
],
"results.limited_legal_acting": [
null
],
"results.initials": [
null
],
"results.contact_email_address": [
null
],
"results.business_type": [
null
],
"results.source_system": [
null
],
"results.gender": [
null
],
"results.last_name": [
null
],

"results.customer_status": [
null
],
"results.date_of_birth": [
null
],
"results.type": [
null
],
"results.customer_id": [
null
],
"results.kvk_sync_available": [
null
]
}

here is the response :
{
"translationMap": {},
"translationMapDefaults": {},
"successTemplate": "${rawResult}"
}

and here is the output contract:
{
"title": "Output",
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"title": "contact ",
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"street_name": {
"type": "string"
},
"zip_code": {
"type": "string"
},
"country": {
"type": "string"
},
"city": {
"type": "string"
},
"house_number": {
"type": "string"
}
},
"additionalProperties": true
},
"contact_phone_number": {
"type": "string"
},
"date_updated": {
"type": "string"
},
"limited_legal_acting": {
"type": "boolean"
},
"initials": {
"type": "string"
},
"contact_email_address": {
"type": "string"
},
"business_type": {
"type": "string"
},
"source_system": {
"type": "string"
},
"gender": {
"type": "string"
},
"last_name": {
"type": "string"
},
"customer_status": {
"type": "string"
},
"date_of_birth": {
"type": "string"
},
"type": {
"type": "string"
},
"customer_id": {
"type": "string"
},
"kvk_sync_available": {
"type": "boolean"
}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}

No i mean that when ever the results are null it goes into the event handler
image

thanks for helping out !

Hey Jerry,

When you run in test mode, you should be able to click the "line" for "execute", which will then show you what the remote endpoint returned. It looks like you are posting the final "flattened" output of the data action.

--Jason

1 Like

A data action can cause your flow to take the success/failure/timeout paths, but it can not force it to go to the event handler. Going to the event handler often means that you are trying to use a value in your architect flow that turns out to be null. I think that "is set" is the architect method you need to use to check if variables are null prior to using them.

I hear you, but the reality is different I am afraid. I cant even switch on it even it is null. It just breaks and goes to the event handle and there nothing to route on. Do you have other examples of users saying that the in particular scenarios the data action breaks?

Hi Jason , what I know is that if the failure route is hit then it is more likely the data action generate a 404 not found error message. What happens here is, it is not a empty empty value. It s a value null and therefore it is a 200OK message. But the data action doesnt like null and if one is not able to fix or change into something then null it breaks.

What I am looking for a fix in translation map and or success template. here is what I have tried today:


and this the new output contract
{
"title": "Output",
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"title": "contact",
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"zip_code": {
"default": "0",
"type": [
"string",
"null"
]
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}

and here is the success output initial value

and here is piece of the flow

Best regards

Hi Jason,

new findings , if the run action is executing the test flattend , then the raw result is this
{
"errors.code": [
"backend_error"
],
"errors.message": [
"BOSS"
],
"results.address.zip_code": [
null
]
}

but if it is unflattend then it looks like this :
{
"results": [
{}
],
"errors": [
{
"code": "backend_error",
"message": "BOSS"
}
]
}

why is it different?

hope to hear from you :slight_smile:

best regards
Jerry

Hey Jerry,

In order to get the raw response from the endpoint, try clicking on the "9 Execute" in test mode. It should look like this:

As to the failures in architect. You may need to have a decision like isSet(Flow.customerMaster_zipcode) to check if that variable is null, prior to trying to get the first element of the array.

--Jason

How can I check Flow.customerMaster_zipcode this variable and at what moment? I am so sorry if I sound irritated but I think I dont't quit understand what you are trying to tell me. What I am telling you is that , how can I manipulate Flow.customerMaster_zipcode? As soon as the call hits the data action and it tries to resolve the variable it goes into the error message. in other words, are you telling me that i can check the variable at the question mark?

regards
jerry

I think that you have the right idea. In the success path of the data action you might have to have a decision block to decide if that variable is null or not.

It would still be helpful to see what you are getting from the execute step.

--Jason

Here is the execution step when nothing is found :
image

flow:

and this is the raw result that goes along with the execution step from the screenshot :slight_smile: {
"errors.code": [
"backend_error"
],
"errors.message": [
"BOSS"
],
"results.address.street_name": [
null
],
"results.address.zip_code": [
null
],
"results.address.country": [
null
],
"results.address.city": [
null
],
"results.address.house_number": [
null
],
"results.contact_phone_number": [
null
],
"results.date_updated": [
null
],
"results.limited_legal_acting": [
null
],
"results.initials": [
null
],
"results.contact_email_address": [
null
],
"results.business_type": [
null
],
"results.source_system": [
null
],
"results.gender": [
null
],
"results.last_name": [
null
],
"results.customer_status": [
null
],
"results.date_of_birth": [
null
],
"results.type": [
null
],
"results.customer_id": [
null
],
"results.kvk_sync_available": [
null
]
}

once this API does find data like zipcode and other stuff it all works fine except when it is coming like here above with null.
-Jerry

So I think that the UI is doing something crazy in the "JSON" block. If you look at the results of the flattening step you will see that there is no actual results.* with a single result of null.

So what is almost certainly happening is that results.address.zip_code is "unset" or null. So when you try to reference it with

results.address.zip_code[0] you are trying to get a value out of a null array, which is going to blow up your architect flow.

Use the is_set() method to make sure that the zipcode isn't null prior to trying to get anything out of it.

--Jason

Hi @Jerry_Sileon_sileo80,

As @Jason_Mathison mentioned try to use IsSet function to validate your list before accessing it. You can also use !isNotSetOrEmpty(YourListName) and Count(YourListName) != 0 as a validation condition as well.

Hi @mostafaawad ,

how would this look like in de flow and where to put it?

i did this !isNotSetOrEmpty(Common.addressZipCode) and Count(Common.addressZipCode) != 0 and put it in a decision block. is that correct ? or do i need to do more to get it working

-Jerry

Hi guys,

here is what happens when the test is unflattend :
image
you can see there is a default attached to from the output contract.

once it gets flattend it wil remove the default from the output contract.
image

So in other words , I think the result.address.zip_code isn't there at all.
so to check the variable is going to be hard if isn't there right?

-Jerry

Yes, this will be definitely in a decision block.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.