Select to view content in your preferred language

Smart Form Calculated Expression to Update Attributes of Parent Feature from Related Table

345
0
09-27-2023 06:36 AM
Labels (1)
marksm_macomb
Frequent Contributor

Hello!

I have an attribute rule that I've been using in Enterprise/Portal that I am trying to (hopefully) re-create in AGO smart forms. The parent features are manholes, and the related table are inspection forms. There are certain attributes (conditions/dates) from the most recent inspection form that I want written to the parent manhole each time a new inspection is submitted. Here is the original attribute rule that is currently working for me in Portal (on the related table):

 

//Forgein Key in child table
var fk = $feature.ParentGUID_

//Load all inspections of the feature
var inspections = $featureSet
var related_inspections = Filter(inspections, 'ParentGUID_ = @fk')

//Filter out record if delete trigger
if($editcontext.editType == "DELETE") {
    var pk = $feature.GlobalID_1
    related_inspections = Filter(related_inspections, "GlobalID_1 <> @pk")
}

//Filter most recent inspection date
var last_inspection = First(OrderBy(related_inspections, "Date_Time DESC"))

//Return nothing if no records found
if(IsEmpty(last_inspection)){
return {
    "edit": [{
        "className" : "DBO.ssManhole_z",
        "updates": [{
            //selecting the parent feature to update
            "globalID" : fk,
            //Update the Condition fields in parent feature class 
            "attributes" : {
                'Cover_Condition': null,
                "Adjust_Ring_Condition": null,
                "Frame_Condition": null,
                "Seal_Condition": null,
                "Chimney_Stu_Condition": null,
                "Cone_Stu_Condition": null,
                "Wall_Stu_Condition": null,
                "Bench_Stu_Condition": null,
                "Channel_Stu_Condition": null,
                "Step_Stu_Condition": null,
                "LastInspectionDate": null,
            }
        }]
    }]
}
}

//Update Condition fields in parent feature class
return {
    "result": $feature.Cover_Condition,
         "edit": [{
            "className" : "DBO.ssManhole_z",
               "updates": [{
                 //selecting the parent feature to update
                 "globalID" : last_inspection.ParentGUID_,
                 //Update the Condition fields in parent feature class 
                 "attributes" : {
                'Cover_Condition': last_inspection.Cover_Condition,
                "Adjust_Ring_Condition": last_inspection.Adjust_Ring_Condition,
                "Frame_Condition": last_inspection.Frame_Condition,
                "Seal_Condition": last_inspection.Seal_Condition,
                "Chimney_Stu_Condition": last_inspection.Chimney_Stu_Condition,
                "Cone_Stu_Condition": last_inspection.Cone_Stu_Condition,
                "Wall_Stu_Condition": last_inspection.Wall_Stu_Condition,
                "Bench_Stu_Condition": last_inspection.Bench_Stu_Condition,
                "Channel_Stu_Condition": last_inspection.Channel_Stu_Condition,
                "Step_Stu_Condition": last_inspection.Step_Stu_Condition,
                "LastInspectionDate": last_inspection.Date_Time,
            }
        }]
    }]
}

 

First off, is this even possible? I'm thinking I pretty much need to change up the return statements at the end to work in an AGO smart form but my brain is having a hard time getting there. Obviously the "class name" in my original return statements are not pointing to the hosted feature service, so that would need to change. Is this a situation where the Push function comes into play? A different REST operation? This is where I get lost.

Thanks in advance for your help!

0 Kudos
0 Replies