UI action on User form

Joshuu
Kilo Sage

Hi All,

 

I have a requirement where in we have a "send text" UI action button on the user form. 

 

Whenever we click on this, a dialogue box should appear with the following fields.

 

User number - should auto populate

Message - blank text box

Send button at the bottom

 

So as soon as we send a message user should receive that message to their phone number.

 

Please assist.

10 REPLIES 10

@Joshuu 

so what did you start with and where are you stuck?

are you saying SMS?

If yes then did you setup your instance for SMS to phone numbers?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Yes, it is SMS to the user's phone number. And yes, in the notify_number table I can see the numbers are configured.

 

I have just created an ui action as send text. Could you please suggest how to proceed further?

@Joshuu 

what did you start with after creating the UI action?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Klaus W Kuhl Br
Tera Guru

To fulfill this requirement in ServiceNow, you can create a "Send Text" UI Action that opens a custom dialog box (using GlideModal or a similar ServiceNow modal dialog utility) and integrate with a third-party SMS service (like Twilio, Nexmo, etc.) for sending the message.

 

You can learn more about Glide Modal in here

I would recommend the Twilio integration for this case, you can learn how to integrate in here

 

The Ui Action script would look something like this:

 

new GlideModal('send_text_dialog').render();

 

 

The UI Page, should be created using the ID informed in the script above, in this case "send_text_dialog" and would look something like this:

 

<div>
    <label for="userNumber">User Number:</label>
    <input type="text" id="userNumber" name="userNumber" readonly="readonly" value="${userNumber}"/>
    <label for="message">Message:</label>
    <textarea id="message" name="message"></textarea>
    <button id="sendButton">Send</button>
</div>
<script>
document.getElementById('sendButton').addEventListener('click', function() {
    var userNumber = document.getElementById('userNumber').value;
    var message = document.getElementById('message').value;
    // Call a Script Include to send the message
    var ga = new GlideAjax('SendMessageScriptInclude');
    ga.addParam('sysparm_name', 'sendMessage');
    ga.addParam('sysparm_user_number', userNumber);
    ga.addParam('sysparm_message', message);
    ga.getXMLAnswer(function(response) {
        alert(response); // Alert the response
    });
});
</script>

 

 

You also will need to create a script include to handle the job and would look something like this:

 

var SendMessageScriptInclude = Class.create();
SendMessageScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    sendMessage: function() {
        var userNumber = this.getParameter('sysparm_user_number');
        var message = this.getParameter('sysparm_message');
        
        // Implementation to send SMS via an API (e.g., Twilio, Nexmo)
        var response = this.sendSMS(userNumber, message);
        
        return response; // Return the response to the client
    },

    sendSMS: function(userNumber, message) {
        // Here, you'd use the RESTMessageV2 API to send the SMS
        // This is a placeholder for the actual implementation
        // The implementation depends on the SMS service provider's API

        return "Message sent successfully to " + userNumber; // Placeholder response
    }
});

 

 

Note: The actual implementation of sendSMS will vary based on the API provided by your SMS service (like Twilio or Nexmo). You would typically use ServiceNow's RESTMessageV2 API to make the HTTP request to the SMS service.

Hi @Klaus W Kuhl Br ,

 

Yes, we have installed Twilio in our instance.