Forum Discussion

donaldlundgren1's avatar
donaldlundgren1
Qrew Trainee
5 years ago

Passing Date Field and Rid to my codepage

I am using the below code in a html code page but I need to pass my Date Field and my rid to this codepage. I am displaying the codepage in my form so that there is a countdown till due.


<p id="demo"></p>

<script>

var countDownDate = new Date("8-10-2019").getTime();


var x = setInterval(function() {


  var now = new Date().getTime();


  var distance = countDownDate - now;


  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);


  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";


  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

The var countDownDate is where I need to get my fid 166 from what ever record I happen to open...

The code I am using to display the page is -

"<img data-url='" & [URL 1] & "'" &
" src onerror='(async () => {  var url = this.dataset.url;  this.outerHTML = '<iframe src=${url} width=155px height=50px></iframe>';})();'>"

Can anyone help?

5 Replies

  • So despite Dan Diebolt's recent inactivity, I can just feel him counting my sins from wherever he may be, but I'm going to try my best and give the solution I would do in a pinch.

    Basically, I would divide the HTML into variables around the dates/IDs you want to use, e.g.
    Name: [URL 1-1]
    Value: <p id="demo"></p>
    <script>
    var countDownDate = new Date("
    and so on, then in the Formula using [URL 1-1] & ToText([Date]) & [URL 1-2] etc., etc. Hope it works for what you're doing, and good luck!
  • AustinK's avatar
    AustinK
    Qrew Commander
    I always just put the info I need into the URL that goes to the code page. Then you can pluck it out of there using things like window.location and parsing the URL. Just add the information you need on to the end like ?rid=xxxx and then parse it on the page.

    I'm not sure that is going to do it when using an iframe though. You might still be able to send that info along.
    • AustinK's avatar
      AustinK
      Qrew Commander
      Instead of doing "var url = this.dataset.url;" you should build it outside of that. It looks like you are just using a formula field so build the URL outside of your JavaScript and insert it where ${url} is now. You want the exact same url as you currently use except you add additional things tot he end and then parse them out when you reach the destination page.

      You don't have to make it exactly like this, it can be done on one line. Just an example to kind of break it out further.

      var text url = "myurl.com/db/whatever/a=e?blah";
      var text urlTwo = "?rid="&[Record ID#];
      var text urlThree = "?date="&[Date Field];

      $url&$urlTwo&$urlThree

      That creates "myurl.com/db/whatever/a=e?blah?rid=14976?date=01-01-2019"

      When you load that URL you then use window.location and parse the URL for the things you need. 

      https://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/