85
Views
9
Comments
Solved
Failed to deserialize JSON when passing local variable record list to table record

Hi All,

I am new on using JSON serialize and JSON deserialize method.
I tried to pass local variable list record from pop up widget to display on parent screen's table record by using JSON serialize and JSON deserialize method. But it fails to deserialize.

"Failed to deserialize JSON to FixedAssetMasterDetailRecordList: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'ssDemo.RestRecords.JSONRCFixedAssetMasterDetailRecord[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List "

This is my parent screen.

This is Parent Screen On Notify action.











This is Parent Screen's Preparation.








This is my Pop Up Screen.

This is Pop Up form Save action's flow.


mvp_badge
MVP
Rank: #96
Solution

Hi Gwen,

As we are holding the newly added record locally to the List Variable and for the newly created record the Id attribute value is 0 because of that very reason I introduced a Index attribute to the Local FixedAssetMasterCreationDetail RecordList Variable as shown below

The other thing which you should observe is the passed input parameter Index value to the PopUpEditorFixedAsset Screen. On the AddRecord Link the passed Index value is -1 and in case of EditRecord Link the passed Index value is the actual record Index attribute value --> I did such implementation in order to distinguish the Add/Edit operation and to get the actual record position in case of record edit.

Please find the attachment -- Included code comments for better visibility and understanding

Questions

1. It is because of the Id attribute = 0, so the Index keep returning value -1?

I'm not using the Id attribute value any more --> For ListIndexOf server action filter condition, I'm referring the newly introduce Index attribute value (as we observed that the Id attribute value for newly added record is 0 so no point in referring the same)


Hope this helps you!


Regards,

Benjith Sam

JSONSerializeTest.oml

mvp_badge
MVP
Rank: #96

Hi Gwen,

Please try the below solution

I guess from the popup screen -- the save action flow is passing a record value in JSON serialized format and in the Parent Screen OnNotify action your are trying to deserialize the serialized JSON string which is a record to RecordList type because of which it is throwing the error.

If the above statement is not solving the problem, please share the serialized JSON string and the structure definition information

Some Questions

- Purpose of defining Destination node in the Popup screen Save action flow? (I think it's not required - it should be end node)

- Parent screen preparation logic - where the code is deserializing the JSON string (not the correct flow - instead you should use the OnNotify implementation in the parent screen)


Hope this helps you!


Regards,

Benjith Sam

mvp_badge
MVP
Rank: #96

Hi Gwen, 

Thank you for sharing the .oml file. I had checked the code and did some required code changes, please have a look on the attached updated .oml file.

See this sample app 


Hope this helps you!


Regards,

Benjith Sam

JSONSerializeTest.oml

mvp_badge
MVP
Rank: #96

Hi Gwen,

As you observed that the "index -1 is out of range"  error is causing because of the ListIndexOf server action returned value -1  which is been used to refer a specific list record in the next action flow assignment node. 

Because of the newly added list record the Id attribute is 0 value and the ListIndexOf server action is using the same Id attribute value for filter condition and as there was no matching record the ListIndexOf server action returned -1 value.

Question

1. Is it possible to pass the data without ID? As I was planning to display the data in table record without saving the data into the database first.

Yes, it is possible and for that you will have to add some additional logic.... Please see the attached updated .oml file.

See this sample app

The mentioned use-case is bit complicated in terms of implementation because you are dealing with a set of data which is not saved in the database i.e. stored locally, and passing the same data set from parent screen to popup screen for edit purpose is something which I felt bit challenging... not yet got any idea regarding this.. let me know your thoughts for this implementation.

Hope this helps you!


Regards,

Benjith Sam

JSONSerializeTest.oml

mvp_badge
MVP
Rank: #96
Solution

Hi Gwen,

As we are holding the newly added record locally to the List Variable and for the newly created record the Id attribute value is 0 because of that very reason I introduced a Index attribute to the Local FixedAssetMasterCreationDetail RecordList Variable as shown below

The other thing which you should observe is the passed input parameter Index value to the PopUpEditorFixedAsset Screen. On the AddRecord Link the passed Index value is -1 and in case of EditRecord Link the passed Index value is the actual record Index attribute value --> I did such implementation in order to distinguish the Add/Edit operation and to get the actual record position in case of record edit.

Please find the attachment -- Included code comments for better visibility and understanding

Questions

1. It is because of the Id attribute = 0, so the Index keep returning value -1?

I'm not using the Id attribute value any more --> For ListIndexOf server action filter condition, I'm referring the newly introduce Index attribute value (as we observed that the Id attribute value for newly added record is 0 so no point in referring the same)


Hope this helps you!


Regards,

Benjith Sam

JSONSerializeTest.oml