396
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.


2021-03-18 21-03-15
Benjith Sam
 
MVP
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
UserImage.jpg
Gwen

Benjith Sam wrote:

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

 Hi Benjith,

Thanks for your kindness, patience and detail explanation!
Much appreciate! 

 

2021-03-18 21-03-15
Benjith Sam
 
MVP

Gwen wrote:

 Hi Benjith,

Thanks for your kindness, patience and detail explanation!
Much appreciate!

You are welcome, Gwen :)

I'm happy and glad that it helped you to solve the problem :)


Regards,

Benjith Sam

2021-03-18 21-03-15
Benjith Sam
 
MVP

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

UserImage.jpg
Gwen

Benjith Sam wrote:

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

 Hi Benjith,

The structure I defined like this. I will share the oml here. The screen I developed is FixedAssetDetail2.


Answered Questions
1. The purpose of defining destination node in the Popup screen in Save action flow is to return to Parent Screen. After your question, I found out that is not required too. Thanks for pointing me out.

2. I not sure how the data should be displayed when page load, so I try to implement the logic in OnNotify in Preparation too.

 

Thank you!

JSONSerializeTest.oml
2021-03-18 21-03-15
Benjith Sam
 
MVP

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
UserImage.jpg
Gwen

Benjith Sam wrote:

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

 Hi Benjith,

Thanks a lot for your help!
But I faced this error where the index position is not found.

I tried debugged and found out it does Serialize the current record into JSON format (refer figure 1), and pass to Parent's Screen (refer figure 2)

Figure 1: Popup Screen Save Action FlowFigure 2: Parent's Screen (FixedAssetDetail2) OnNotify Flow

 When comes to "ListIndexOf", the output data is different from the above figure. So, it returns error as the position is not found..


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.


2021-03-18 21-03-15
Benjith Sam
 
MVP

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
UserImage.jpg
Gwen

Hi Benjith, 

Thank you for your detailed explanation! 

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.

The idea for this implementation is due to my working project requirement.
For this Detail information, I actually wanted to make it works like Editable Table. Some reasons for this implementation:
1. There are about 30 columns of data to display and for user to fill in. Almost all of the data are mandatory to fill in.

2. Editable table can be apply in Item 1, but it does not fit in terms of user experience, as user have to scroll along the horizontal bar to look and fill in for detail.

3.To prevent the inconsistency of the ID of this Detail Entity with another Master Data Entity. There is a form request to fill in which tie with this Detail information. Before submit the form request, this Detail information have to store locally. After submit form request, then only create with ID. So, the main point I stuck with is how to display the data which is not saved in the database.


Besides, I try create a record in your Sample App, it can fetch and display the data. But for my case, it does not display the data. Below figures are my find out from debug.

 

Questions

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


2021-03-18 21-03-15
Benjith Sam
 
MVP
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
UserImage.jpg
Gwen

Benjith Sam wrote:

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

 Hi Benjith,

Thanks for your kindness, patience and detail explanation!
Much appreciate! 

 

2021-03-18 21-03-15
Benjith Sam
 
MVP

Gwen wrote:

 Hi Benjith,

Thanks for your kindness, patience and detail explanation!
Much appreciate!

You are welcome, Gwen :)

I'm happy and glad that it helped you to solve the problem :)


Regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.