Select to view content in your preferred language

Relationship not working as it should on Smart Forms - New MapViewer

1378
10
Jump to solution
06-28-2023 03:22 PM
GustavoMiralesSilva
New Contributor III

Hi there folks, 

Lately i've been working on a project to manage data in our company, it's very simple. It's a web page that users can input some data, e add reports on that data from time to time.

For that, i've created a point feature and and a related table. In WebApp Builder, through Smart Forms, it's possible to add the points, and the related records, very simple. BUT, working with WAB, i can't take advantage on some very useful Arcade functions and page layout it's kinda frozen, soooooo, i went to New MapViewer/Experience Builder to try.

I became very excited when i saw that is possible to add related records with the form editor, until i find out that it just won't work! The relationship between points and reports it's done by the GlobalID field in the point feature, but when I try to create a related record, it won't populate the related field on the new record.

The funny thing is that when I tried to do the same thing on FieldMaps, it works like a charm.

This is not the first time that i find problems with the form on New MapViewer, and have to go back do Old MapViewer and WebApp Builder, and not taking advantage on some cool features on Experience Builder.

Is this expected? Seems New MapViewer Form works very differently from FieldMaps, what should i do?

EDIT

Problem solved. The issue was the way I've created the relationship classes.

The relationship was created through REST API's Add to definition, with the request:

{
   "layers":[
      {
         "id":0,
         "relationships":[
            {
               "id":1,
               "name":"relationship_name",
               "relatedTableId":1,
               "cardinality":"esriRelCardinalityOneToMany",
               "role":"esriRelRoleOrigin",
               "keyField":"GlobalId", //Here was the issue
               "composite":false
            }
         ]
      },
      {
         "id":1,
         "relationships":[
            {
               "id":1,
               "name":"relationship_name",
               "relatedTableId":0,
               "cardinality":"esriRelCardinalityOneToMany",
               "role":"esriRelRoleDestination",
               "keyField":"GlobalID_FROM_PARENT_LAYER",
               "composite":false
            }
         ]
      }
   ]
}

The issue was, that the key field I've used on the parent layer was not indentical, the correct field name was "GlobalID", with the capital "D". It seems that this may not be a issue with other apps, such as WebAppBuilder. So, when creating new relationship classes through the REST API, be careful with that.

So, I've got the job done by adding this to definition of the layer:

{
   "layers":[
      {
         "id":0,
         "relationships":[
            {
               "id":1,
               "name":"relationship_name",
               "relatedTableId":1,
               "cardinality":"esriRelCardinalityOneToMany",
               "role":"esriRelRoleOrigin",
               "keyField":"GlobalID", //Name fixed
               "composite":false
            }
         ]
      },
      {
         "id":1,
         "relationships":[
            {
               "id":2,
               "name":"relationship_name",
               "relatedTableId":0,
               "cardinality":"esriRelCardinalityOneToMany",
               "role":"esriRelRoleDestination",
               "keyField":"GlobalID_FROM_PARENT_LAYER",
               "composite":false
            }
         ]
      }
   ]
}

 

Big thanks to @CraigGillgrass, with the help to work that out.

0 Kudos
1 Solution

Accepted Solutions
CraigGillgrass
Esri Regular Contributor

Thanks @GustavoMiralesSilva - this makes sense with what we're seeing.  The issue is the following:

  • The Primary Key in the Empreendimento layer is "GlobalID"
  • In the relationship class json, the "GlobalID" field is referred to as "keyField" : "GlobalId" - note the lowercase "d"

This is a casing issue; it's not possible to create a relationship class like this through Pro - so we're looking at how we/if can fix this.  In your case, the fix should be to delete the relationship class and recreate it ensuring the casing matches.  That should address the issue.

If it doesn't - let me know - we can keep looking into it.

View solution in original post

0 Kudos
10 Replies
RussRoberts
Esri Notable Contributor

Have you checked out this blog for how to setup the related record element and then the form element for the related records? 

https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/introducing-related-record-editing-i...

0 Kudos
GustavoMiralesSilva
New Contributor III

No, didn't saw that. But still doesn't work.

I've followed the steps as this publication instructs, and got the same results. The GUID field of the parent Featue Layer will not populate de child table, it leaves it null, resulting on a lost record without relatioship at all.

I've also tried to do it on a brand new MapViewer, from scrach, and got the same results.

0 Kudos
CraigGillgrass
Esri Regular Contributor

Hi @GustavoMiralesSilva is it possible to invite my public user, "craig_sp", to the Group with the feature service and map so I can take a look at the data?  We had a few issues around GUIDs that we addressed at the end of the release, but they were around the use of calculated expressions.  It doesn't sound like that is your issue.

I'd like to look at your data so I can see if I can determine what is happening.

Craig

0 Kudos
GustavoMiralesSilva
New Contributor III

Sure, I just sent you the invitation.

The content is in portuguese, so feel free to message me if you need anything. 

This morning I erased all data to see if the problem was the old data, and it was not. This is in development, so there's only test data.

Thank you.

0 Kudos
CraigGillgrass
Esri Regular Contributor

thanks @GustavoMiralesSilva I've got the data and I've been able to reproduce the issue - we're taking a look and will report what we find here.

CraigGillgrass
Esri Regular Contributor

@GustavoMiralesSilva we've tracked down the issue and it has to do with how the relationship class is defined.  Can you help us to look at this by explaining how you created the point feature layer, related table and relationship class?

thank you, Craig

0 Kudos
GustavoMiralesSilva
New Contributor III

Cheers Craig,

The point feature layer  and the table I believe was created in a file geodatabase in ArcGIS Pro. I've create the first layer and then uploaded into ArcGIS Online, wich created a hosted feature layer. After uploaded I've deleted the original geodatabase from AGOL, left only the hosted FL.

The relationship was created through the REST API, since we only have ArcGIS Pro basic, where creating relationship classes are not licenced. Here's the python code for it:

def add_relationship_class(feature_layer_url, relationship_name, origin_layer_number, origin_layers_field, 
                           to_layer_number, to_layer_field, cardinality, origin_rel_id, to_rel_id, composite=False):

    new_relationship = {
        "layers" : [
            {
                "id": origin_layer_number,
                "relationships": [
                    {
                        "id" : origin_rel_id,
                        "name" : relationship_name,
                        "relatedTableId" : to_layer_number,
                        "cardinality" : cardinality,
                        "role" : "esriRelRoleOrigin",
                        "keyField" : origin_layers_field,
                        "composite" : composite
                    }
                ]
            },
            {
                "id": to_layer_number,
                "relationships": [
                    {
                        "id" : to_rel_id,
                        "name" : relationship_name,
                        "relatedTableId" : origin_layer_number,
                        "cardinality" : cardinality,
                        "role" : "esriRelRoleDestination",
                        "keyField" : to_layer_field,
                        "composite" : composite
                    }
                ] 
            }
        ]
    }

    url = f'{feature_layer_url}/AddToDefinition?token={_TOKEN}'
    add_json = json.dumps(new_relationship)

    payload = {
        'addToDefinition': add_json,
        'async': 'false',
        'f': 'json',
        'token': _TOKEN
    }

    session = requests.Session()
    result = session.post(url, data=payload)

    return result.json()

Then, just ran:

add_relationship_class(feature_layer_url, 0, 'GlobalID', 2,'Guid_from_parent_layer', 'esriRelCardinalityOneToMany', 1, 1)

 

Just to be aware, the actual code it's a little bit different when I ran, there's other functions such as get the connection token, get the feature url, and the next available relationship number, I've striped those parts to keep it short and readable, but you'll get the point. Never had a problem using WAB with this, so i believed it was ok.

0 Kudos
CraigGillgrass
Esri Regular Contributor

Thanks @GustavoMiralesSilva - this makes sense with what we're seeing.  The issue is the following:

  • The Primary Key in the Empreendimento layer is "GlobalID"
  • In the relationship class json, the "GlobalID" field is referred to as "keyField" : "GlobalId" - note the lowercase "d"

This is a casing issue; it's not possible to create a relationship class like this through Pro - so we're looking at how we/if can fix this.  In your case, the fix should be to delete the relationship class and recreate it ensuring the casing matches.  That should address the issue.

If it doesn't - let me know - we can keep looking into it.

0 Kudos
GustavoMiralesSilva
New Contributor III

Hi@CraigGillgrass, we're on the way.

I'm having a hard time deleting the relationship through the REST API. I think using the same relationship id for both relationship objetcs may not be a good thing (https://community.esri.com/t5/arcgis-rest-api-questions/remove-relationships-from-published-services...). I've tried to use the API's Delete From Definition, ended up not deleting it, and botch the whole thing. The Form try to load the relationship and get stuck.

This relationship thing through API is little documented, so i'm aware it is risky. Because of that, I always make a new Feature Hosted Layer as a copy from the FL i want to change, and do testing on it. I did it again today, and voila!

The new FL made from a copy it's working like expected. The related record now is being populated with the GlobalID from parent. You can try for yourself, I just added to the group.

Is interesting that the "keyField" in this new FL is still "GlobalId" (with the "d" in lowercase), so, I can't say if that was the issue, and aparently I've messed up the main FL. Maybe the copy created a new property that was missing?

I guess I'll have to re-do the Feature Layer, using propper relationships ids and correct field names. I'll report my progress then. Thanks!!

0 Kudos