How to add new line in client script

priyankagavali
Tera Contributor
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) {
   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

piyushsain
Tera Guru
Tera Guru

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

Aniket Chavan
Tera Sage
Tera Sage

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