How to save a JS Var to a field

edited February 4, 2020 in Questions
Hi everyone, 

I have been trying to get some javascript to grab the gps geolocation of the user when a js snippet is run and add this to a couple of fields (longitude / latitude ).

My issue is saving the var to the fields - 

This is my js ( I think this works ok)...

navigator.geolocation.getCurrentPosition(function(position) {  
  var gps = (position.coords.latitude+position.coords.longitude);  
  window.GlobalVar = gps;
Does anyone have any ideas how to get this to work?


  • Mark DeSimoneMark DeSimone 🛠️ 
    edited February 4, 2020
    Hi Matt. It sounds like you may be able to use the updateRow API for this:

    I would recommend reading through this document top to bottom for a great introduction on using Javascript with Skuid:

    I've linked to the part of the document that mentions the updateRow API so you can see an example.
  • edited January 9, 2019
    One common pattern in Skuid Pages is to have a Ui-Only Model called "Vars" or "PageVars", which has a single row in it (which gets created on page load using "Create default row if model has none". Then you can save data to various fields in that Model from your code, e.g. like this:
    navigator.geolocation.getCurrentPosition(function(position) {  
    var PageVars = skuid.$M("PageVars");
      PageVars.updateRow(PageVars.getFirstRow(), { "Latitude": position.coords.latitude, "Longitude": position.coords.longitude });

    Then, anywhere in Skuid, you can grab the value of the Latitude / Longitude in the Action Framework, or using Merge Syntax, or you can display the Latitude / Longitude in a Field Editor --- whatever you want.
  • edited January 9, 2019
    Thanks for the suggestions guys. 

    I will be updating two fields on the model (which are fields on the SF object)... Latitude__c and Longitude__c.
    The object / model is called "ThisWeeksRosters."

    I came up with the following but it still doesn't seem to work...

    navigator.geolocation.getCurrentPosition(function(position) {      var PageVars = skuid.$M("PageVars");    $.each(,function(i,row){           ThisWeekRostersModel.updateRow(row,{       "Latitude": position.coords.latitude,       "Longitude": position.coords.longitude  });    continueSomeProcess();;  });
  • edited January 9, 2019
    Your code is using "Latitude" and "Longitude", but in your comment you say the fields are called "Latitude__c" and "Longitude__c". Can you try that code again but use the api names of the fields?
  • edited January 9, 2019
    Echo what Ben says --- also i don't see where "ThisWeekRostersModel" is defined. 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!