JavaScript for sending SMS

469 views
Skip to first unread message

Neelesh Kadam

unread,
Dec 28, 2017, 9:29:46 AM12/28/17
to mementodatabase
Hi

I have been a user of Memento for a long time.
Until recently I found out the option of Javascript field.
I have a library from which I need to send SMS to the selected contact in library with a text from one of the library field.
Currently I am doing it manually and have to do it every time I create or edit the entry. Which has become a bit of hassle.
I am not good at doing programming so tried coping one of the readily available scripts but it fails.
Attached are screenshots of the library structure and Javascript that I had copied.
Text field - "V"
SMS to contact in field - "N"

Can some one help me with writing a Javascript for sending sms.

Thanks in advance.
Neelesh

Happy New Year
Screenshot_2017-12-27-13-56-19.jpg
Screenshot_2017-12-27-13-56-41.jpg
Screenshot_2017-12-27-13-55-57.jpg

Bill Crews

unread,
Dec 28, 2017, 10:32:13 AM12/28/17
to Neelesh Kadam, mementodatabase
I wish I knew more about this stuff and could hemp better, but here are my thoughts, anyway...

Attached are screenshots of the library structure and Javascript that I had copied.
Text field - "V"

I notice V is an Integer, which in JavaScript is a Number, not a String. When you use it later, maybe it'll work right or maybe not. Maybe try something like msg + " "?

It gets an error on intent()? I don't understand that. intent() is a global, like message(). It should not have a problem. You might try System.intent(), but I don't know why you'd need it.


Tomasz K.

unread,
Dec 28, 2017, 6:13:24 PM12/28/17
to mementodatabase
Hey.
Try the same with the trigger.
In Java field may not work.

Neelesh Kadam

unread,
Dec 29, 2017, 5:15:41 AM12/29/17
to mementodatabase
Hey Bill
Thanks for the help.
After your suggestion checked if the first line of the code works as "V" is an integer. And found out that there is no problem with it.
The code I have used is as follows

msg = entry().field("V");
i = intent("android.intent.action.SENDTO");
i.data("smsto:"+entry().field("N"));
i.extra("sms_body" , msg);
i.send();

It gives the reference error: "intent" is not defined (field.js#3)

I tried using system.intent but the error remains same.

So after searching how to define intent I tried the following

intent i = intent("android.intent.action.SENDTO");

Now the error changes to - missing ; before statement

Can you suggest what can be done next.

Neelesh Kadam

unread,
Dec 29, 2017, 5:18:16 AM12/29/17
to Tomasz K., mementodatabase
Hi

Thanks for the reply.
Tried using Trigger as suggested, but could not figure out the way to send a text after a new entry is created or a existing editors.

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "mementodatabase" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mementodatabase/a6zv3nK42B0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mementodatabase+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tomasz K.

unread,
Dec 29, 2017, 6:01:42 AM12/29/17
to mementodatabase
The script will work the way you want.
Set:
Creating a new entry or Updating an entry
After saving the entry or Before saving the entry.
You choose the option you want.

http://wiki.mementodatabase.com/index.php/Trigger_Examples

W dniu piątek, 29 grudnia 2017 11:18:16 UTC+1 użytkownik Neelesh Kadam napisał:
> Hi
>
>
> Thanks for the reply.
> Tried using Trigger as suggested, but could not figure out the way to send a text after a new entry is created or a existing editors.
>
>
> Thanks
>
>
> On 29 Dec 2017 04:43, "Tomasz K." <tomasz...@gmail.com> wrote:
> Hey.
>
> Try the same with the trigger.
>
> In Java field may not work.
>
>
>
> --
>
> You received this message because you are subscribed to a topic in the Google Groups "mementodatabase" group.
>
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/mementodatabase/a6zv3nK42B0/unsubscribe.
>
> To unsubscribe from this group and all its topics, send an email to mementodataba...@googlegroups.com.

Eoprava sk

unread,
Aug 15, 2022, 3:39:54 PM8/15/22
to mementodatabase
How to add custom text before and after field? 

msg = "your device" entry().field("DeviceID") is in state "entry().field("State");


i = intent("android.intent.action.SENDTO");
i.data("smsto:"+entry().field("N"));
i.extra("sms_body" , msg);
i.send();

The required things are just custom text in BOLD marked areas. Thank you



Dátum: piatok 29. decembra 2017, čas: 12:01:42 UTC+1, odosielateľ: Tomasz K.

Bill Crews

unread,
Aug 15, 2022, 6:21:46 PM8/15/22
to Neelesh Kadam, mementodatabase
system.intent(...) should have been Staten.intent(...).

intent() is a global function within the System object. It is invoked using a prefix of "System.", unlike a method, which would be invoked with an instantiated object such as is returned by the System.intent() method. Note that JavaScript is case sensitive, so system.intent() won't work, as Memento has no system object, though it does have a System object. data() is a method of an instantiated Intent object returned by System.intent(). So if you have...
var i = System.intent(«Indent type»);
Then, you can use i.«This method»() or i.«That method»() to accomplish what you want.

I hope this helps.

--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.

Bill Crews

unread,
Aug 15, 2022, 6:23:41 PM8/15/22
to Neelesh Kadam, mementodatabase
CORRECTION...

system.intent(...) should have been System.intent(...).

Eoprava sk

unread,
Aug 17, 2022, 6:42:42 PM8/17/22
to mementodatabase
One more question. I managed to figure this out, it sends SMS. Figured out the way to merge fields with custom text. 
I just wanted to add Switch which decides multiple text options. Sending my script below.

var state= entry().field("state");
var msg
switch (msg) {
  case "Delivered":
    msg = "Your device was accepted in repair center. ";
   
  case "Awaiting diagnostics":
    msg = "Diagnostics are running on device. Our technician will contact you soon.";
   
  case "Sent back":
    msg = "Your device has been sent back. You can expect package tommorow";

   
 
}
i = intent("android.intent.action.SENDTO");
i.data("smsto:"+entry().field("Phone"));

i.extra("sms_body" , msg);
i.send();

This script opens SMS on phone but as message it´s written "undefined"

Thank you for help


Dátum: utorok 16. augusta 2022, čas: 0:23:41 UTC+2, odosielateľ: bill....@gmail.com

Bill Crews

unread,
Aug 17, 2022, 9:01:22 PM8/17/22
to Eoprava sk, mementodatabase
what is pretty much always needed is the first line of the error message issued at the same time as the undefined. The most needed part of that is the "JS#xx", where xx identities the line of your script where the error occurred.

If the text you sent was line for line identical to what's in you script editor, then someone here should be able to help you identify the problem. Some variable or object referenced on that line was not known to the JavaScript engine.

Looking at the script, I see that you are using the value of msg to determine which case should be executed, but msg has yet to be given a value. Trying to access it with switch might very likely result in undefined. I think you intended to switch on state rather than msg.


Er Mo

unread,
Aug 18, 2022, 2:42:16 PM8/18/22
to mementodatabase
var state= entry().field("state");
var msg
switch ( state ) {

  case "Delivered":
    msg = "Your device was accepted in repair center. ";
   
  case "Awaiting diagnostics":
    msg = "Diagnostics are running on device. Our technician will contact you soon.";
   
  case "Sent back":
    msg = "Your device has been sent back. You can expect package tommorow";

   
 
}
i = intent("android.intent.action.SENDTO");
i.data("smsto:"+entry().field("Phone"));

i.extra("sms_body" , msg);
i.send();

Versuche das
Ernst

Craig Hunter

unread,
Dec 15, 2022, 8:39:50 AM12/15/22
to Eoprava sk, mementodatabase
I'm not sure why it says "undefined", but I think your switch needs
break;
statements/clauses

Best to have a
default:
statement/clause

I am not sure but it might help to not change the msg inside the switch.

Suggestions added, but not tested:

switchMsg = msg;

switch (switchMsg) {

  case "Delivered":
    msg = "Your device was accepted in repair center. ";
   break;

  case "Awaiting diagnostics":
    msg = "Diagnostics are running on device. Our technician will contact you soon.";
   break;

  case "Sent back":
    msg = "Your device has been sent back. You can expect package tommorow";
break;
default: {
message("something bad happened");
cancel();
Reply all
Reply to author
Forward
0 new messages