Adding more then one rows from a form at once and finalizing them

Hi
I want to access the Instance ID of the row I want to edit, on the edit screen

I have checked odkData.js, odkCommon.js, odkSurvey.js but couldn’t find a clue.
If anyone could help me through this,

ODK2.0 Survey

regards

Dear @MirwaisAkrami,

Could you explain a bit more what you are trying to do? Do you want to display the instance id or change it? I would not advise at all changing the instance id by editing a row by hand, as that is likely to cause all sorts of problems. If you just want to display, that tends to be one of the hidden fields in ODK, but I would think you could make a note prompt that shows it.

Best,
Caroline

@MirwaisAkrami as @elmps2018 said it would be useful to know a bit more about what you are trying to do so we can help more.

Maybe if I provide some more information it will help you to better understand that instanceID is more of a concept than an exact value. Each row in the database has a unique “rowId” (simply called id) that is metadata column you can query but i do not think you change it.

To allow users to have a useful “instance name” you can set the instance name shown to the users in the setting tab of your excel workbook. The “instance name” corresponds to whatever value in the database table you set it to. Therefore, if you wanted an editable instance name then simply make a value in the table that is the “viewable” to the user instance name and then set the ‘instance_name’ variable on the settings tab to use that column of the database as the ‘instance_name’. This value will become like any other value you can have a prompt about it, display questions about it, change it, run calculates on it, etc.

See the documentation for more information about the ‘instance_name’: https://docs.opendatakit.org/odk2/xlsx-converter-reference/#settings

I hope this post was helpful. If not, please provide more information so we can help direct you to other features that might be useful to accomplish your task.

Thanks for the reply @elmps2018 and @W_Brunette,
well, I want to make a custom subform for household members in which I want to add more then one members, using the methods provided by the .js files but I am facing the following problems
1: When I add the new row using addRow method of odkData.js, the record is not finalized .
2: One extra row is added to the member table and on finalizing the subform only that row is finalized.

and that Instance ID issue, I have solved that by using method ‘getInstanceId(refId)’ from odkSurveyStateManagement.js.

Thanks

@MirwaisAkrami glad that you found the instance id and that is resolved.

So it sounds like you are working in Tables rather than Survey? My experience is from the Survey perspective, where, yes, when you add a household member it is automatically started as incomplete (not finalized). Then when you finalize that subform (member row), it is only finalized for that particular member. From at least the Survey perspective this process is discussed here:

https://docs.opendatakit.org/odk2/survey-using/#saving-a-form-instance

I think it is intentional to have to finalize (because then the whole form gets rechecked) and to only finalize one (sub)form at a time. Is there something in particular that is causing a problem with that workflow? Maybe if you can explain your goal more that would help.

Best,
Caroline

Sorry for the late reply.

Dear @elmps2018, as I mentioned in the previous replies, I want to add more then one rows in one instance of the subform, (Normally you can add only one)
These are the Issues I face
1: One extra row is added to the table always (This row is only finalized on the NEXT page), I want that it must not be added to the table.
2: as I am adding new rows to the table they are still obviously INCOMPLETE. What I want is that all these newly added rows should show up for finalization on the next page without that extra added row which should be not present in the first place.

Hope I have cleared myself
Regards

@MirwaisAkrami sorry but I think I am still a little confused about what you are trying to do.

It sounds like you are trying to add multiple rows that are the same instance of the subform.

However, as I understand it, an instance of a subform should = a row in the table. So for example if you want to add household members, each would be an instance of the subform. They could have the same household id, for example, but the members themselves need to be separate instances. Otherwise when you do thinks like sync they may all over-write each other and be very difficult to distinguish, etc. If you are trying to use the same instance id for multiple rows, this may be what is generating odd behavior.

I do not know any way to finalize multiple instances at once, generally you complete one and finalize that so that if you have any problems you can correct them before the next.

Hope that helps!

Best,
Caroline

@elmps2018, as you mentioned I am adding multiple rows from one subform at once and want to finalize all of them in the next page and I do assign unique instance IDs to each and every row and all of them having the same parent ID,

So my actual problem is that I cannot finalize all of them at once, looking for some help regarding this

Regards

An update - refId

I can get refId from the odkSurveyStateManagement.js using method _refId(), however this gives nothing on my android device cause its a mock implementation of the real interface, after I searched the code I found that this method was not implemented in the interface in the app but I found this method in MainMenuActivity.java, So is there any way for me to get refId on the device

below are two screeshots of the code

1: MainMenuActivity - getRefId()
odk1

2: OdkSurveyStateManagement - getInstanceId(refId)
odk2

@MirwaisAkrami, thanks for your responses. I am still a bit confused as to why you need to generate multiple rows with a subform. Subforms were intended to be used to add one additional row at a time that links back to the parent form. If I had a better understand of your use case, I may be able to be more helpful.

However, if you want to generate and save multiple rows of data at once, you would probably be better served by writing your own custom JavaScript in a Tables app. Take a look at our injected JavaScript Interfaces in ODK Tables (https://docs.opendatakit.org/odk2/injected-interfaces/?highlight=javascript%20api#other-system-survey-js-files). Information about getting started with ODK Tables is at https://docs.opendatakit.org/odk2/tables-sample-app.

well, the requirements of the survey I am working on is such that the subform rows and their values are dependent on each other, means that I must put values of for example second row according to the values of the upcoming rows, that’s why I want to first validate them altogether and then push them one by one to the database.
I have solved the problems of adding them to database and finalizing them also, but one problem still exist that is, ODK survey creates one instance for the subform, and I want to get it’s Instance ID so I can overwrite it cause it is inserted with null values (Something I deliberately do ).
So in app designer I can get it using odkSurveyStateManagement as follow

refId

but in real environment i.e Android device, the first line of code gives error as the method getRefId() is not implemented in the odkSurveyStateManagement Interface injected by java, but the second method works as it is present in that interface.
So this is my problem ms @clarice_larson.
How to access refId in android device?

@MirwaisAkrami, I am very interested in seeing your Survey at this point. If you could share it on the forum, that would be great. If sharing it publicly is not possible, perhaps you could send it to my clarlars@gmail.com address.

Try using opendatakit.getCurrentInstanceId() to get the instanceId. There is also an opendatakit.getRefId() function. As Survey was intended to work on one row of data at a time and I am unsure where you would be attempting to make these function calls, the variables behind these getter functions may not have been set properly yet, but give them a try. As a side note, functions beginning with an ‘_’ are considered to be private and not for public consumption.