Select to view content in your preferred language

Assigning more than one occupant to a single unit.

438
1
01-31-2024 03:57 AM
AbhyanshuGupta
New Contributor III

Hi,

I am creating a custom space planner application in the application i want the behaviour in such a way i can allocate a single room to multiple users, how can i achieve this like when we assign an occupant to any unit the unit stores the name of the occupant in Known As field, the occupant stores the unit id of the unit allocated to them etc. So what all steps will i be performing for allocation more than one occupant to the room. I have written the following code for the assigning of a single occupant to the room:

  const occupantsLayer =getLayerByTitle("Occupants")

const unitsLayer = getLayerByTitle("Units");

    var unitQuery=unitsLayer.createQuery();
    unitQuery.where = `NAME = '${globalUnitName}'`;
    unitQuery.outFields = ["*"];    
    var query= occupantsLayer.createQuery();
    query.where = `KNOWNAS= '${name}'`;
    query.outFields = ["*"];
    occupantsLayer.queryFeatures(query).then(function(result){       
       var occupant=result.features[0];
       console.log("occupant data",occupant);
       unitsLayer.queryFeatures(unitQuery).then(async function(res){
        var feature=res.features[0];
        console.log("unit data",feature);
        feature.attributes.ASSIGNMENT_TYPE="office";
        feature.attributes.KNOWNAS=name;    
        feature.attributes.EMAIL=occupant.attributes.EMAIL;
        feature.attributes.JOB_TITLE=occupant.attributes.JOB_TITLE;
        occupant.attributes.UNIT_ID=feature.attributes.UNIT_ID;
        occupant.attributes.LEVEL_ID=feature.attributes.LEVEL_ID;
        occupant.geometry.x=feature.geometry.centroid.x;
        occupant.geometry.y=feature.geometry.centroid.y;      
        console.log("oc after",occupant);
        console.log("un after",feature);
       
        var occupantUpdate=[{
            attributes:occupant.attributes,
            geometry:occupant.geometry
        }]
        console.log("update occupant",occupantUpdate);        
        await LayerApplyEdits(occupantsLayer,{ updateFeatures:occupantUpdate})
       
        var updates = [{
            attributes: feature.attributes,
            geometry: feature.geometry
        }];  
        await LayerApplyEdits(unitsLayer,{updateFeatures:updates});
 
What all changes do i have to make for the assigning part so that i can allocate more than one occupant to a single unit?
0 Kudos
1 Reply
KadeSmith
Occasional Contributor

I'm curious why you are doing this as a custom application? The Space Planner allows you to assign multiple occupants per unit right out of the box. You can then move them around in the room as well so that you can read the names better. 

0 Kudos