How to identify /n from a string and set its value in next line

snowuser111
Kilo Guru

HI All,

I have a string which is supposed to be identified with /n for next line and set the value in Incident Description field accordingly.

Example:

This is servicenow new version release \n please go through wiki for more details \n Contact support team for any issues \n Thanks

I want to set above in Incident field- description ,in this way where \n is meant for next line.

This is servicenow new version release

please go through wiki for more details

Contact support team for any issues

Thanks

Can Anyone put your thoughts on this or idea how do I proceed through scripting.

8 REPLIES 8

Hi Loris,



Thanks for the idea.


Sorry about the confusion . Whole String contains \n and has to be set in incident 'Description' field. So will it automatically break the string and bring it next line??


I can not use g_form because it is coming via REST API in a field. I am doing this in Transform script.



Whole String has to be retrieved from the source field and has to be set in target 'description' with next lines.


So you just need to set the 'Description' field to be a Multi-Line text (by setting the Mar Length in the dictionary to a value >= 256 ).


Any \n occurrence in the string will be rendered as new line


lorisd_avanzo
ServiceNow Employee
ServiceNow Employee

So I have tried the below code



[Client Side]


var str = "This is servicenow new version release \n please go through wiki for more details \n Contact support team for any issues \n Thanks";


g_form.setValue("short_description",str);



[Server Side]


var gr = new GlideRecord ("incident");


gr.get("71e0fa504750210042bd757f2ede2730");


var str = "This is servicenow new version release \n please go through wiki for more details \n Contact support team for any issues \n Thanks";


gr.short_description = str;


gr.update();



The variable named str in the above two pieces of code is the same you have posted.



They both (Client/Server sides) work fine, you just need to have the Short Description defined as Multi-Line text box in order to configure the capability of rendering the actual new lines.


For that matter, you would need to change the Dictionary of the Short Description field and set the Max Length field to a value greater than 255.


Ref: http://wiki.servicenow.com/index.php?title=Introduction_to_Fields#gsc.tab=0


See the String row:


StringCharacter string. For String type fields, a length of under 256 appears as a single-line text field and anything 256 characters or over appears as a multi-line text box.



Regards,


Loris


So basically


source.u_description = "This is servicenow new version release \n please go through wiki for more details \n Contact support team for any issues \n Thanks"



required


target.description =



This is servicenow new version release


please go through wiki for more details


Contact support team for any issues


Thanks