question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

embedded_list reference fields do not work

See original GitHub issue

I have an edit view with an embedded list field that has sub-fields of reference type and they do not work properly. There is no call to the rest api asking for the list in this example.

        nga.field('editResultsId', 'embedded_list')
            .label('Edit Results')
            .targetFields([
                nga.field('fileSystemId', 'reference')
                    .label('File System')
                    .targetEntity(file)
                    .targetField(nga.field('name'))
                    .validation({ required: true }),

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:11
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
dowlingwcommented, Jul 7, 2016

I had a quick look at this today but wasn’t able to make much progress - had to figure out how things hang together. Leaving some notes as @etdev was keen to look at this also.

Crud/routing.js creates a bunch of ui-router resolve definitions based on the model coming out of the admin-config library.

It looks like lib/Utils/ReferenceExtractor in admin-config is the culprit, it only looks at the top level object and doesn’t traverse complex fields.

Took a quick stab at fixing this but I’ve run out of time to look at it this week and it doesn’t work. Here’s the code so far, it’s a recursive function to find all the reference fields during a call to getReferences.

let find_references = function(fields, recurse_func) {
    let result = new Array();

    fields.forEach(function(field, idx) {
        if( field.type() === 'reference' || f.type() === 'reference_many' ) {
            result.push(field);
        } else if( field.type() === 'embedded_list' ) {
            result.push( recurse_func( field.fields(), recurse_func ) );
        }
    });

    return result;
};
let references = find_references(fields,find_references);

Cheers 😃

4reactions
jbrownD3commented, Nov 22, 2016

WORKAROUND – While waiting for the pull-request to be completed, I found an easy workaround. Just add the same reference field to your top level object (make it hidden, non-editable, not required). As long as you use the same object in .targetEntity() in both the top level and embedded, you will get a populated list. Below I just used an empty label and non-editable field, but you can use CSS to hide the field row as well.

`
var wtEntity = nga.entity('webapp_templates');
var embeddedFields = [
        nga.field('webapp_template', 'reference')
            .targetEntity(wtEntity)
            .validation({required: true})
            .targetField(nga.field('context_name'))
            .detailLinkRoute('show'),
        ...  //Other embedded fields
];
var parentFields = [
        nga.field('webapps', 'embedded_list')
            .targetFields(embeddedWebappsFields),
    ...  //Other parent fields
        nga.field('webapp_template', 'reference')   //Workaround for reference in embedded list
            .targetEntity(wtEntity)  //Same entity object, not just another entity with the same name
            .editable(false)  //non-editable keeps the control from showing
            .label('')  //no label
            .validation({required: false})  //not required so it won't error
            .targetField(nga.field('context_name')),  //not sure this is needed, but I left it
];

`
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regarding Reference Field in Embedded List - ServiceNow
The embedded list contains a reference field. ... Yes, by the time you open the record in the table, you dont have submit...
Read more >
Embedded Data - Qualtrics
For a vast majority of users, embedded data field names are no longer case-sensitive, meaning “test” and “Test” would be treated as the...
Read more >
List View formCompleting the Display Fields tab - Pega
Embedded ? Select if the output display of this list view is to appear within the run time presentation of another rule, such...
Read more >
Reference fields | Mastering ServiceNow - Second Edition
Scripting, lists, and forms all understand references fields, as we'll see while we work through the chapters. Creating a reference field. Let's think...
Read more >
Embedded lists Archives - ServiceNow Guru
... could show and hide an embedded related list on a form. I just created some client scripts to accomplish this task so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found