Copying a field content to another

rob_blakey
Tera Expert

Hi ServiceNow Community,

I am having some scripting issues attempting to copy the following:

I created a new field within the Change Management Module called "Change Description". The reason for this is that I wanted to have the change description field HTML but not impact the description field that sits across the task table.

What I would like to do is copy the text content from the Change Description field "u_change_description_html" into the standard "description" field.

I have attempted business rules and client scripts, but nothing I have tried seemed to help. I did see a few comments about this in other forums however, nothing seemed to work for me.

If anyone has any suggestions or has already created a script for this it would be greatly appreciated.

Regards,

Rob

1 ACCEPTED SOLUTION

salemsap
Tera Expert

use regular expression to remove the html tags like below,


copy the below code and paste it in the business rules.


var text = current.u_change_description_html.toString();


var regX = /(<([^>]+)>)/ig;


var finalText = text.replace(regX, " ");


current.description = finalText;



try and lemme know if any issues


View solution in original post

13 REPLIES 13

Try something like following code this in Business rule



var str   = current.u_change_description_html;


str =   str.substring(str.indexOf('>##'),str.indexOf('##<'));


current.description = str;


I would like it to remove all HTML tags not just the #..



eg. remove the <p> and styles and font-size etc.. all HTML related tags and convert it to plain text


Well you could do that too by adding or subtracting character sequence .



str =   str.substring(str.indexOf('>##')+1,str.indexOf('##<')+2);


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi @rob_blakey,



Write a onSubmit client script with the following code. Please let me know the outcome.


function onSubmit() {


  //Type appropriate comment here, and begin script below


  var des = g_form.getValue('u_change_description_html');


  var StrippedString = des.replace(/(<([^>]+)>)/ig,"");


  g_form.setValue('description',StrippedString);



  //Type appropriate comment here, and begin script below


}


If there are symbols, tags will still be displayed.