Skip to main content
Nintex Community Menu Bar
Question

How to save a JS Var to a field

  • July 11, 2024
  • 5 replies
  • 1 view
  • Translate

Forum|alt.badge.img+6

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) {&nbsp;&nbsp;<br>&nbsp; var gps = (position.coords.latitude+position.coords.longitude);&nbsp;&nbsp;<br>&nbsp; window.GlobalVar = gps;
&nbsp; continueSomeProcess();<br>});


Does anyone have any ideas how to get this to work?

Did this topic help you find an answer to your question?
This topic has been closed for comments

5 replies

Forum|alt.badge.img+9
  • Nintex Employee
  • 889 replies
  • July 11, 2024

Hi Matt. It sounds like you may be able to use the updateRow API for this:

https://docs.skuid.com/latest/en/skuid/api/skuid_model_model.html#skuid.model.Model.updateRow

I would recommend reading through this document top to bottom for a great introduction on using Javascript with Skuid:
https://docs.skuid.com/latest/en/skuid/javascript/skuid-javascript.html#updating-a-row

I’ve linked to the part of the document that mentions the updateRow API so you can see an example.

Translate

Forum|alt.badge.img+13

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&#46;geolocation&#46;getCurrentPosition(function(position) {  <br /> var PageVars = skuid&#46;$M("PageVars");<br />  PageVars&#46;updateRow(PageVars&#46;getFirstRow(), { "Latitude": position&#46;coords&#46;latitude,``` "Longitude": position&#46;coords&#46;longitude });

continueSomeProcess();

});<br /><br />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.
Translate

Forum|alt.badge.img+6
  • Author
  • 63 replies
  • July 11, 2024

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(ThisWeekRostersModel.data,function(i,row){ ThisWeekRostersModel.updateRow(row,{ "Latitude": position.coords.latitude, "Longitude": position.coords.longitude }); continueSomeProcess(); ThisWeekRostersModel.save(); });
Translate

Forum|alt.badge.img+8

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?

Translate

Forum|alt.badge.img+13

Echo what Ben says — also i don’t see where “ThisWeekRostersModel” is defined. 

Translate

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings