Not able to copy description with line Breaks from UI Action to UI Page

Deepika18
Tera Guru

Hi All,

 

I have created an UI Action on Case form to create a Incident with all the information available on Case.

 

As "Service Offering" is not available on Case I have created a dialog box using UI Page and GlideModal asking for service offering.

 

But now everything is fine except the description is not getting copied with Line breaks. The Line breaks are getting disappeared in HTML in UI Page. 

Requesting you to help me with this issue.
@Ankur Bawiskar 

1 ACCEPTED SOLUTION

@Deepika18 

I was able to use solution from that link and used text area in HTML

UI Action:

AnkurBawiskar_0-1750859534856.png

 

UI Page:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:ui_form>
		<g:evaluate var="jvar_sysid"
					expression="RP.getWindowProperties().get('sysid')"/> 

					
Description: <textarea id="description" rows="10" cols="30" name="description" value=""/>
			</g:ui_form>
</j:jelly>

Client Script:

addLoadEvent(function(){
	var m = GlideModal.prototype.get("showHTMLLineBreaks");
	var p = m.getPreference("description");
	document.getElementById("description").innerHTML = p; //create div with same id in HTML and set the innerHTML to the preference we grabbed from the Client Script
});

Output

AnkurBawiskar_1-1750859587296.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

11 REPLIES 11

@Deepika18 

UI page will remove line breaks

check this link for workaround, there are 2-3 approaches, I showed 1

Try the easiest approach and see if that works

How can I show line-breaks from string field in UI Page 

1) in UI action when you pass replace line breaks with <br> tags

function copyCaseToIncident() {

    var sysId = g_form.getUniqueValue();

    var caseDesc = g_form.getValue('description') ;
    alert(caseDesc);

    caseDesc = caseDesc.replace(/\n/g, '<br></br>'); //input <br> tags

    var openedBy = new GlideAjax('getOpenedBy');
    openedBy.addParam('sysparm_name', 'openBy');
    openedBy.addParam('sysparm_caseID', sysId);
    openedBy.getXMLWait();
    var user = openedBy.getAnswer();

    var createIncWindow = new GlideModal("CreateIncident");
    createIncWindow.setTitle("Create Incident");
    createIncWindow.setBackdropStatic(true);
    createIncWindow.setWidth(700);
    createIncWindow.setPreference("sysparm_sys_id", sysId);
    createIncWindow.setPreference("sysparm_short_description", g_form.getValue("short_description"));
    createIncWindow.setPreference("sysparm_description", caseDesc);
    createIncWindow.setPreference("sysparm_assignedTo", g_form.getValue("assigned_to"));
    createIncWindow.setPreference("sysparm_assignmentGrp", g_form.getValue("assignment_group"));
    createIncWindow.setPreference("sysparm_callerID", user);
    createIncWindow.render();
}

2) in UI page client script add this -> I couldn't find the HTML id for Description, you use your one

addLoadEvent(function(){
    var m = GlideModal.prototype.get("CreateIncident");
    var p = m.getPreference("sysparm_description");
    document.getElementById("yourHTMLDiv").innerHTML = p; //create div with same id in HTML and set the innerHTML to the preference we grabbed from the Client Script
});

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Deepika18 

I was able to use solution from that link and used text area in HTML

UI Action:

AnkurBawiskar_0-1750859534856.png

 

UI Page:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:ui_form>
		<g:evaluate var="jvar_sysid"
					expression="RP.getWindowProperties().get('sysid')"/> 

					
Description: <textarea id="description" rows="10" cols="30" name="description" value=""/>
			</g:ui_form>
</j:jelly>

Client Script:

addLoadEvent(function(){
	var m = GlideModal.prototype.get("showHTMLLineBreaks");
	var p = m.getPreference("description");
	document.getElementById("description").innerHTML = p; //create div with same id in HTML and set the innerHTML to the preference we grabbed from the Client Script
});

Output

AnkurBawiskar_1-1750859587296.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar I have add the HTML content you provided at the top of the existing HTML code and Client script in between of existing client script.

But confused what to be modified at processing script end. and also where are we calling the function we added in client script

@Deepika18 

check my latest response and enhance your code.

Also in your UI page HTML I couldn't find any html element which is rendering that input box for Description, so curious to know how it's getting rendered

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar ,  

<input type="hidden" aria-hidden="true" name="inc_description" value="$[sysparm_description]" />

 

this is the line from where we are getting description from sysparm_description and storing it in inc_description and calling that in processing script

 

var description = typeof inc_description !== "undefined" ? inc_description : "";

 

And in your latest script, you are not calling the description variable anywhere in the processing script. I tried it and the dialog window is not coming now (kinda not working)