Google App Maker - Add a button for timestamp coll

2020-05-08 06:30发布

I searched high and low and cannot find a specific answer that works. I need to add a button to a form in App Maker to record a timestamp, not a date, when clicked. So far the only thing that I've managed to get to work is

widget.datasource.item.Timestamp_OUT = new Date();

I've also tried

var timestamp = getTimeStamp();

But keep getting an error "ReferenceError: "getTimeStamp" is not defined". I'm probably missing the obvious as it shouldn't be this difficult to do something this simple. Any help is appreciated, thanks.

2条回答
【Aperson】
2楼-- · 2020-05-08 07:17

Success! With the help of everyone here and the guys at this link: Google Groups - Solution I've managed to crack the case (and learn some stuff along the way).

Everything originally above works just fine if you take the " + " out of the function so it reads

function getTimeStamp(){
var timestamp = new Date();
return timestamp;
}

Then, onclick of

var timestamp = getTimeStamp();
widget.datasource.item.Timestamp_IN = timestamp;

Next, format the table to show the correct data with

@datasource.item.Test_Timestamp#formatDate('EEEE \x27at\x27 h:mm:ss a')

And "Hey Presto!" you get a button that, when clicked, gives you a timestamp. Thaks to everyone who pitched in, you're the reason people who are learning continue to do so and don't throw in the towel when things get difficult :)

查看更多
放荡不羁爱自由
3楼-- · 2020-05-08 07:19

Based on your comment:

You got almost everything right with a couple of exceptions. So your getTimeStamp function should look like this:

function getTimeStamp(){
    var timestamp = + new Date();
    return timestamp;
}

That is, because you have to return a value. The other problem is that when you are assigning the value to the datasource item, you don't have to use the keyword new; therefore, it should be like this:

var timestamp = getTimeStamp();
widget.datasource.item.Timestamp_IN = timestamp;

The above is basic javascript. I recommend you to dig into javascript before moving forward with appmaker.

查看更多
登录 后发表回答