spModal.alert add new lines in message

triciav
Kilo Sage

I had a previous question and was able to get some assistance with that.

However I am now trying to get the spModal alert to display each of the answers from my GlideAjax onto individual lines

I was able to look at the link and get the spModal,

 

However I am having the same issue now with the spacing

 

How do I get this to be with line breaks

So for each of the Conference Names I need them to be on their own line

List of Conferences already registered

My Conference
My New Event
Test

etc.. so the below would have each conference name on its own line?

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

 

var ga = new GlideAjax('ConfAjaxUtils'); //x_btig_bookings.ChoiceAvailable

ga.addParam('sysparm_name', 'getExisting');

ga.addParam('sysparm_table', "u_conferences");

ga.getXML(getresponse);

 

function getresponse(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

if (answer) {

 

var names = + '\nng =onference Names " + '\n;' + answer);

spModal.open({

"title":" + answer);

spModal.open({

"title": "Exisitng Conference Names",

"message": "List of Conferences that have already been registered. " + names,

"buttons" : [

{label: "✘ Cancel New Registration" , primary: true},

{label: "✔ Register New Conference" , cancel: true}

],

"backdrop" : "static",

"keyboard": false

}).then(function(answer){

//g_form.setValue('license_type' , 'free');

});

 

}

}

}

 

 

1 ACCEPTED SOLUTION

I see.

I tried the approach with the spModal and the way I got it to work, was to return all the data with line breaks, formatted as HTML, from the script include.

Can you try it that way?

So the script include should return a text that looks like this:

"Conference name 1" + "<br>" + "Conference name 2" + "<br>" + ...

In my previous response you got it working with an alert, but the difference is that the alert handles newlines differently from the spModal, so it should have text as this:

"Conference name 1" + "\n" + "Conference name 2" + "\n" + ...

View solution in original post

12 REPLIES 12

triciav
Kilo Sage

I still need some help on this please:

How can I get this to load when the variable changes without the user having to click the "Check existing Conferences button" ?

So when the user changes the variable to New Conference I need to have the spModal popup without the user having to click anything.

Thank you so much!!

This is my Catalog Widget:

HTML:<button ng-click="c.onConfirmEx()" class="btn btn-default">
Check - Existing Conferences
</button>
<span>{{c.confirmed}}</span>

 

This is my Client Controller:

function($scope, $rootScope,$uibModal, $location,$window,spUtil,spModal) {
var c = this;
c.onConfirmEx = function() {
spModal.open({
"title": "List of Conferences that have already been registered",
"message": "Do not Register a Confernce that already exists. Use the Modify Option instead. "+"<br>"+c.data.got,
"buttons": [{
label: "✘ Cancel New Registration",
primary: true
},
{
label: "✔ Register New Conference",
cancel: true
}
],
"backdrop": "static",
"keyboard": false
}).then(function(confirmed) {
c.confirmed = confirmed;
//g_form.setValue('license_type' , 'free');

});
}

}

 

This is my Server Script:

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */

var confItems = [];
var table = 'u_conferences';
var elm = 'u_conference_name';

var choicesGR = new GlideRecord('sys_choice');
choicesGR.addQuery('table', table);
choicesGR.addQuery('element', elm);
choicesGR.query();
var names = '';
while (choicesGR.next()) {
names += choicesGR.getValue('label')+"<br>";
data.got = names;
}

})();

find_real_file.png

Somchai Laotee
Tera Contributor

The basic of style sheet.

 

Servicenow : Client script

var names ='<pre>'+ '\nng =onference Names " + '\n;' + answer+'</pre>;

 

Servicenow : CSS file.

 

pre {
width: 100%;
padding: 0;
margin: 0;
overflow: auto;
overflow-y: auto;
height:222px;
font-size: 14px;
line-height: 20px;
border: 0px solid #777;
background-color: #ffffff;
font-family: "Kurious Looped";
font-weight: 300;
font-style: normal;
font-display: swap;
tab-width: 4;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word;
}

Rajyalakshmi
Tera Contributor

 

you have to use HTML tags for formatting the message and <br> is the HTML tag for a new line.

 

Regards,

Raje