Save graphics to feature layer and update attribute value ?

549
2
Jump to solution
04-21-2019 05:12 AM
MayurDodiya
Occasional Contributor

Hi,

I am saving graphics in feature service and I would like to add/update Attribute values to feature was just added

Below is the code I am able to Save graphics to Feature layer Service.

function createfreehandline (graphic)
{

   var freeHLayer = this.map.getLayer('freeHLayer'); // Layer added in map Feature Service layer

freeHLayer.applyEdits([graphic], null, null).then(function (adds, updates, deletes) {
console.log('success', adds);

}, function (err) {
console.log(err);
});

}

For Example, with above code new feature with ObjectId added, now I want to update attribute value in Field name "JOBNO" 

How can I update the attribute value of feature that was just added ?

0 Kudos
1 Solution

Accepted Solutions
MayurDodiya
Occasional Contributor

Hi Ken,

Thanks for your reply.

After adding below line I was getting error " Cannot set property 'JOBNO' of undefined"

graphic.attributes["JOBNO"] = newAttribute;

So, I Created new object then add attributes to object and set to graphic. Below code worked for me



var SaveAttribute = new Object();
SaveAttribute.JOBNO= newAttribute;
graphic.attributes = SaveAttribute;
freeHLayer.applyEdits([graphic], null, null).then(function (adds, updates, deletes) {
 console.log('success', adds);
 }, function (err) {
 console.log(err);
 });

Thanks,

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Honored Contributor

Before you call applyEdits, change the attribute of the graphic to the value newAttribute

graphic.attributes["JOBNO"] = newAttribute;
freeHLayer.applyEdits([graphic], null, null).then(function (adds, updates, deletes) {
0 Kudos
MayurDodiya
Occasional Contributor

Hi Ken,

Thanks for your reply.

After adding below line I was getting error " Cannot set property 'JOBNO' of undefined"

graphic.attributes["JOBNO"] = newAttribute;

So, I Created new object then add attributes to object and set to graphic. Below code worked for me



var SaveAttribute = new Object();
SaveAttribute.JOBNO= newAttribute;
graphic.attributes = SaveAttribute;
freeHLayer.applyEdits([graphic], null, null).then(function (adds, updates, deletes) {
 console.log('success', adds);
 }, function (err) {
 console.log(err);
 });

Thanks,

0 Kudos