Dynamically Generated URL Link

Hi, at the end of each flight, I’d like to link to a Google Forms page to log flights for the aircraft. The Form includes a Hobbs In and Hobbs Out time, which are collected as Text Input Items in the checklist. Google Forms allows fields to be pre-filled by including the values in the URL. Is there a way to dynamically create a link that would include values collected form Text Input Items? In addition, it would be great if I could also include the current date (YYYY-MM-DD). The last checklist item would be to log the flight and it would link directly to this dynamically generated URL.

Thanks!

Great question Greg. There is a cool way to do this using what we call String Variables. A previous forum post covers that some which I will link at the bottom of this post. In this post I will cover your specific use case which is a great example of how they can be used.

When you create an Item such as a Text Input, if you add an ID to it under the Advanced panel, then you can use that ID to get the value of the text input.

Say you add an ID to a Text Input you are using for Hobbs Out e.g. hobbsOut. You can then use that in Label content by referencing the ID created.

NOTE I am using the Markdown Editor for the label and the below syntax is how you create a URL Link with the content within the brackets the label for the URL, and the content within the parenthesis () the URL of the link.

[Show Google Form for Logbook](https://forms.google.com/test?testVarHobbsOut=${hobbsOut}&testVarHobbsIn=${hobbsIn})

The ${} will be replaced with the content entered in the input.

NOTE The ID you create can’t have dashes in it or spaces, so as in the example I gave, I use camelCase by capitalizing each word in the ID.

You can also run javascript in the brackets.

new Date().toISOString().split('T')[0]

The above javascript will format a timestamp using the ISO standard and just get the date part of the string which is at the beginning.

Putting it all together with the timestamp in…

[Show Google Form for Logbook](https://forms.google.com/test?testVarHobbsOut=${hobbsOut}&testVarHobbsIn=${hobbsIn}&testVarDate=${new Date().toISOString().split('T')[0]})

UPDATE #1

The above function for getting today’s data is not perfect, because it is getting it in Zulu time, so if you happen to be flying at night where Zulu time is already on the next day, it would be a day off.

This can be fixed with a little more script for getting the date. To make this cleaner, you can create functions in MiraCheck as well which are small scripts. You can then call the function in your expression.

You would copy the content below into your Functions Editor.

function padZero(n) {
  return (n < 10 ? '0' : '') + n;
}

function getDate() {
  // Get the current date
  var date = new Date();
  // Get the month and add 1 because starts with 0, also pad beginning with a 0
  var month = padZero(date.getMonth()+1);//months (0-11)
  // Get the day, also pad beginning with a 0  
  var day = padZero(date.getDate());//day (1-31)
  // Get the full year which is 4 digits
  var year= date.getFullYear();
  // Format - e.g. 2021-11-15
  var formattedDate =  year+"-"+month+"-"+day;
  
  // Return the formatted date
  return formattedDate;
}

You would change your expression to be…

[Show Google Form for Logbook](https://forms.google.com/test?testVarHobbsOut=${hobbsOut}&testVarHobbsIn=${hobbsIn}&testVarDate=${getDate()})

Update #2

All of the above can even be simpler with no functions needed at all if you take advantage of another component we have which is the Date picker.

Step 1

NOTE You can put the Date picker anywhere in the checklist, but make sure it is before the item where you want to use the expression, which in this case is the URL you are dynamically generating.

Step 2

Step 3

Final Expression
You can now use that ID in an expression, so your expression would be…

[Show Google Form for Logbook](https://forms.google.com/test?testVarHobbsOut=${hobbsOut}&testVarHobbsIn=${hobbsIn}&testVarDate=${today})


Let us know if it makes sense and you pull off what you are trying to accomplish.


Original String Variables post…

This worked perfectly, Jeff! I went with the method in Update #1 and it worked great.

Thanks for your help!

1 Like

Always great to hear how users creatively use MiraCheck!