How to add new line in client script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:09 AM - edited 02-09-2024 01:10 AM
How to add new line description field in below client script?
Tried "\n" thing but not working out.
I need description should be look like ,
Description from group: answer
descValue
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
Tried "\n" thing but not working out.
I need description should be look like ,
Description from group: answer
descValue
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var descValue = g_form.getValue('u_description');
var grSysUtils = new GlideAjax('global.sysUtils');
grSysUtils.addParam('sysparm_name', 'getGroupDesc');
grSysUtils.addParam('sysparm_groupName', newValue);
grSysUtils.getXML(updateDesc);
function updateDesc(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (descValue != "") {
//Need to add new line in below line
g_form.setValue('u_description', "Description from group:" + answer + '\n' + descValue);
} else {
g_form.setValue('u_description', answer);
}
}
}
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:20 AM
Hi,
Please try .toString() after answer and descValue. If it does not work please use <br> instead of "\n"
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain
Regards,
Piyush Sain
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:37 AM
Hello @priyankagavali ,
Please give a try to the script below and see how it works for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var descValue = g_form.getValue('u_description');
var grSysUtils = new GlideAjax('global.sysUtils');
grSysUtils.addParam('sysparm_name', 'getGroupDesc');
grSysUtils.addParam('sysparm_groupName', newValue);
grSysUtils.getXML(updateDesc);
function updateDesc(response) {
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
if (descValue !== "") {
// Add a new line using HTML line break tag
g_form.setValue('u_description', "Description from group: " + answer + '<br>' + descValue.toString());
} else {
g_form.setValue('u_description', answer);
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket