Problem with nested references in functions

Hello!

Are there any known issues for retrieving nested references in a function (in a service)?

I am writing a function to duplicate checklists. I pass a section as a parameter to get the section. This works:
section.checklist

However, section.checklist.id returns undefined.

Furthermore, I do something similar for questions. For each question I want get the checklist property from the section. Question.section works, however this:

question.section.checklist (also including .ID) returns undefined. The question is in context.

The data sources used are runtime.

I have already worked around the issue and found a solution, but I would expect these references to resolve correctly… I seem to remember doing this with success earlier? Is this a known limitation in functions, or am I missing something about how nested references are handled in Services?

1 Like

Hi!

Have you had a chance to look at this?

Hi!

Sorry about the late response. Nested references seems to be handled correctly as far as I can see for Services.

Could you share some more information about your setup?

Hi again!

Yes, sure. I have a set of questions and a service variable Map Questions (string). For each question I write to the service variable, a JSON-stringified array to the service variable.

Code:
// MapQuestion is a string holding a JSON array
const current = mapQuestion || "[]";
const arr = JSON.parse(current);
arr.push({newChecklistReferance: checklist, newChecklistId: "Value: " + checklistId});
return JSON.stringify(arr); // write back to MapSection

The function parameters checklist and checklistId are read in like this:

The Map Questions service variable then looks like this:
[{"newChecklistReferance":"6928884dc64007141a06a2ba","newChecklistId":"Value: undefined"},{"newChecklistReferance":"6928884dc64007141a06a2ba","newChecklistId":"Value: undefined"},{"newChecklistReferance":"6928884dc64007141a06a2ba","newChecklistId":"Value: undefined"}]

This shows that the function can retrieve question.checklist, but not question.checklist.id when running in a service. However, in the client I can access both question.checklist and question.checklist.id without issues when using a similar structure.

Is this expected behaviour?:thinking: I get the same result (undefined id) when using the same function to log to console (in the service).

Hi!

Your setup seems to work fine when I try to recreate it (same behavior as apps).

Just to rule it out - You don’t happen to have a reference data source from your QA Checklist Questions to the QA Checklist data source and that the checklist with ID 6928884dc64007141a06a2ba is not present in that data source?

When trying to recreate your case your setup works as expected, but I’m able to reproduce the same behavior if I set up a reference data source from QA Checklist Question to the QA Checklist and making sure that the checklist object for the questions I’m processing is not in that data source. When using the function properties from your example then question.checklist gives the id as it’s a property of the question in context, but question.checklist.id is undefined (as expected as it’s a property of the checklist).

If this is not the case, let me know and I’ll try to do some more digging. :slight_smile: