How to pass params to HYPERLINK formula

Hi, friends!

I have making cattle counter app. When cow calved, I canโ€™t catch them in that time. In many cases I havenโ€™t tool for tagging them on a land. But birthday of calve is very important data for my system. So I have give the new childe temprorary ID. Itโ€™s negative number of calves mom.
For example if cow 60 calved I have give them just -60. And itโ€™s work. This is uniq ID.
When I catch calve in farm I have give them new uniq ID, like 219. But I have make them in manualy, from Google spreadsheet.

This is long proccess for me and I want to make something like form submitting.

So I need to get from 2 inputs and pass them to HYPERLINK formula, that call my GAS API and call function that change ID.

ID - for appsheet is uniq, that not changeable, but for Google Spreadsheet itโ€™s just cell value. After change this value I need just reload appsheet app.

Any idea ?

Solved Solved
0 7 379
1 ACCEPTED SOLUTION

I have maked them right now. And it was very interesting task.

AppSheet and Gas is very good tool.

So, first of all, I have make table with two columns. First column is for old ID and second for new.

In appSheet column setting make type of old ID ref type. Now, I can select ID from drop down list. And second column setting donโ€™t change.

After that, I have make action that open external link and I am use formula hyperlink.

This is example of formula:

HYPERLINK(CONCATENATE("https://script.google.com/macros/s/AIpcX-pSp73kHE-CbgbYzKfhVOCf8/exec?", "find=", [OldID], "&repl=", [NewID]), "")

And on ther server side of GAS, make this script that replace ID and this code looks like this:

function doGet(request) {
  var result = "ะ‘ั–ั€ ะถะตั€ะดะตะฝ า›ะฐั‚ะต ะบะตั‚ั‚ั–";
  if(request.parameter.find && request.parameter.repl){
    result = "ะกั‹ั€า“ะฐ ะฐัƒั‹ัั‚ั‹ั€ั‹ะปะดั‹: "+changeVID(Number(request.parameter.find), Number(request.parameter.repl));
  }else if(request.parameter.resetcounter){
    clearMarked();
    result = "ะกะฐะฝะฐา› า›ะฐะนั‚ะฐ ะฑะฐัั‚ะฐะปะดั‹";
  }
  return ContentService
   .createTextOutput(result)
   .setMimeType(ContentService.MimeType.TEXT)   
}

In this code, I have check by parameters wich function needs to call.
if(request.parameter.find && request.parameter.repl)

After that, I have call function that find and replace ID in my column and replace them to new.
this code I have found on stackoverflow:

function tryChangeVID(f,r, table, col) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(table);
  var range = sheet.getRange(col);
  var values = range.getValues();
  var res = f;
  
  for (var i = 0; i < values.length; i++) {
    if (values[i][0] === f) {
      values[i][0] = r;
      res = r;
    }
  }
  
  range.setValues(values);
  
  return res;
}

function changeVID(find, repl){
  var result = tryChangeVID(find, repl, "Animals", "A:A");
  
  if(result === repl){
    result = tryChangeVID(find, repl, "Calves", "C:C");
  }
  
  return result;
}

This function works like webhook, without any response. But this good desition for my task.

Maybe someone help

View solution in original post

7 REPLIES 7

In my opinion you should use a different data structureโ€ฆ You should have a table for cattle, a table for tags, and a table for pairings in which you connect the cow to the tag. This is better because if the tag getโ€™s compromised and needs to be replaced you donโ€™t change the ID of the cow itselfโ€ฆ Sample App - NFC / Barcode / Geolocation and Foreign Keys

In your case you probably would not need the third parings tableโ€ฆ the tag table will do that jobโ€ฆ

Steve
Platinum 4
Platinum 4

Why not instead copy the temporary rowโ€™s values into a permanent row once you get the tag, the delete the temporary row?

Thatโ€™s a good idea as wellโ€ฆ My only thought is that if heโ€™s interacting with that cow in any other way, then changing the key, or starting a new record is pretty bad ideaโ€ฆ

Another option would be to not use the tag as key.

Itโ€™s not suitable for me, I have tried them before. Because I am use ID another sheets. For example register cow calves. On cow have multiple calves. Also vaccines.

I have maked them right now. And it was very interesting task.

AppSheet and Gas is very good tool.

So, first of all, I have make table with two columns. First column is for old ID and second for new.

In appSheet column setting make type of old ID ref type. Now, I can select ID from drop down list. And second column setting donโ€™t change.

After that, I have make action that open external link and I am use formula hyperlink.

This is example of formula:

HYPERLINK(CONCATENATE("https://script.google.com/macros/s/AIpcX-pSp73kHE-CbgbYzKfhVOCf8/exec?", "find=", [OldID], "&repl=", [NewID]), "")

And on ther server side of GAS, make this script that replace ID and this code looks like this:

function doGet(request) {
  var result = "ะ‘ั–ั€ ะถะตั€ะดะตะฝ า›ะฐั‚ะต ะบะตั‚ั‚ั–";
  if(request.parameter.find && request.parameter.repl){
    result = "ะกั‹ั€า“ะฐ ะฐัƒั‹ัั‚ั‹ั€ั‹ะปะดั‹: "+changeVID(Number(request.parameter.find), Number(request.parameter.repl));
  }else if(request.parameter.resetcounter){
    clearMarked();
    result = "ะกะฐะฝะฐา› า›ะฐะนั‚ะฐ ะฑะฐัั‚ะฐะปะดั‹";
  }
  return ContentService
   .createTextOutput(result)
   .setMimeType(ContentService.MimeType.TEXT)   
}

In this code, I have check by parameters wich function needs to call.
if(request.parameter.find && request.parameter.repl)

After that, I have call function that find and replace ID in my column and replace them to new.
this code I have found on stackoverflow:

function tryChangeVID(f,r, table, col) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(table);
  var range = sheet.getRange(col);
  var values = range.getValues();
  var res = f;
  
  for (var i = 0; i < values.length; i++) {
    if (values[i][0] === f) {
      values[i][0] = r;
      res = r;
    }
  }
  
  range.setValues(values);
  
  return res;
}

function changeVID(find, repl){
  var result = tryChangeVID(find, repl, "Animals", "A:A");
  
  if(result === repl){
    result = tryChangeVID(find, repl, "Calves", "C:C");
  }
  
  return result;
}

This function works like webhook, without any response. But this good desition for my task.

Maybe someone help

Top Labels in this Space