Escobar5
Escobar5

Reputation: 4082

PnP JS Add Item with FieldGeolocationValue - SharePoint

I'm trying to add an item to a list that contains a Geolocation field, I cannot find how to add a value to this field in the docs, I've tried with several ways, no success:

await web.lists.getByTitle('Opiniones')
.items.add({
   ...
   Location: { "__metadata": {"type": "SP.FieldGeolocationValue"}, Latitude: parseInt(req.body.lat||0), Longitude: parseInt(req.body.long||0) 
   ...
}

or this way:

await web.lists.getByTitle('Opiniones')
.items.add({
   ...
   Location: { Latitude: parseInt(req.body.lat||0), Longitude: parseInt(req.body.long||0) 
   ...
}

Upvotes: 0

Views: 323

Answers (1)

Jerry
Jerry

Reputation: 3625

I tested to set location field value using PnP Js like this and it's working as expected:

  pnp.sp.web.lists.getByTitle("Products").items.add({
        Title: "NewLocationAdded",
        Location: {
          "__metadata": {"type": "SP.FieldGeolocationValue"},
          "Latitude": 60.2872339,
          "Longitude": 24.8516785
      }
    }).then(() => {
        console.log("done");
    });

enter image description here

enter image description here

In your side, you could manullay set a double value to Latitude and Longitude directly like above to test if it works.

Upvotes: 1

Related Questions