[SOLVED] Replacing the 0 with a 44 for SMS Printing

Continuing the discussion from SMS Sending Feature:

Background info, my main primary field for Customers is their telephone number. It’s stored as a conventional UK number, so ‘07xxxxxxxxx’ etc.

Setting this up was easy enough, but I was wondering if there was a way to manipulate the string in the printer template so instead of returning 07xxx…, it returns 447xx… ? This is because the API I’m using needs a international country code. (I’m using the Clockwork SMS API - https://www.clockworksms.com/doc/easy-stuff/http-interface/send-sms/)

Also, I presume the SMS itself will need to have the ‘+’ symbol replacing spaces? Will punctuation affect the URL output in the API?


Any ideas?

Try using JScript .substr() function inside an [=expression]

number=[='44' + '{ENTITY NAME:Customers}'.substr(1)]

Same goes for JScript .replace() function in an [=expression]

number=[=('44' + '{ENTITY NAME:Customers}'.substr(1)).replace(/ /g,'+')]
sms=[='Hello, your order has just left Cinnamon for delivery.'.replace(/ /g,'+')]

Thanks for the speedy reply! Apologies for possibly being a blithering idiot here, but does this simply go into the template? If I preview the template, I get invalid bracket syntax.

Because I’m not running the print job in live mode, I get the message box without the JScript, however with the JScript I no longer get the message box?

Sorry, there was a missing closing bracket in the last expression. It is corrected now.

I assume so, since it is a Template that you posted.

I have never used SMS, so I don’t know how it works or how it is configured, or exactly what output you require. But you should be able to extrapolate from the code that I posted.

All works a treat! Thank you so much for your help. Just a further note, the message has to be UTF-8 encoded to work as a URL, so because I’ve got one generic message, I’ve just hardcoded it into the template.

Also for other users who may use the same tutorial above, you may want to limit the use to only mobile numbers as opposed to landlines. This can be done simply by adding a custom constraint to the rule where the SMS is sent to check the entity data number begins with ‘07’ in the UK.

Pretty sure there would be a method for doing this dynamically with jscript but if single message hardcode obviously will do the job.