- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 03:08 PM
Hi ,
I have created a business rule to replace a line in the Description field with empty space .
It is working and that line is replaced with blank space . Now I want to remove this white space and move Up the line below it .
Please guide how to achieve it .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2021 06:42 AM
I just used the same script and it worked fine for me
Original Message
Script:
var gr = new GlideRecord('problem');
gr.get('a463aa81db41e010224a2a9a48961954');
var desc = gr.description;
gs.info('Original String->\n' + desc);
desc = desc.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');
var arr = desc.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
var finalArr = [];
for(var i in arr){
if(arr[i] != ''){
finalArr.push(arr[i].toString());
}
}
var finalString = finalArr.join('\n');
gs.info('Final String->\n' + finalString);
gr.description = finalString;
gr.update();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2021 06:42 AM
I just used the same script and it worked fine for me
Original Message
Script:
var gr = new GlideRecord('problem');
gr.get('a463aa81db41e010224a2a9a48961954');
var desc = gr.description;
gs.info('Original String->\n' + desc);
desc = desc.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');
var arr = desc.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
var finalArr = [];
for(var i in arr){
if(arr[i] != ''){
finalArr.push(arr[i].toString());
}
}
var finalString = finalArr.join('\n');
gs.info('Final String->\n' + finalString);
gr.description = finalString;
gr.update();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2021 04:56 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
If not, please let us know if you need some more assistance.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 05:29 AM
I have tried the business rule by making few changes, below is the script .
It is working fine but the issue I am seeing is , if a variable question has ',' even that is going to a new line .
Also , could you please explain the following line , what is that doing ?
Please suggest .
var arr = value.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
Business rule :
(function executeRule(current, previous /*null when async*/ ) {
var description = current.description.toString();
if (description.includes('Legal Entity Code: LE-')) {
var grdesc = new GlideRecord('sn_hr_core_case');
grdesc.addEncodedQuery('active=true^descriptionLIKELegal Entity Code: LE-');
grdesc.addQuery('sys_id', current.sys_id);
grdesc.orderByDesc('sys_created_on');
grdesc.setLimit(1);
grdesc.query();
if (grdesc.next()) {
var finalArr = [];
var value = description.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');
var arr = value.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
gs.info('the refined arr is :' + arr);
for (var i in arr) {
if (arr[i] != '') {
finalArr.push(arr[i].toString());
}
}
gs.info('my firstarray is :' + finalArr);
var finalString = finalArr.join('\n');
grdesc.description = finalString;
gs.info("my final string is :" + finalString);
grdesc.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 05:37 AM
Hi,
that line will remove the new lines character and replacing with @
I could see that information is variable and variable value
There you can manipulate not to include the variable with name "Legal Entity Code" so that you need not do all the above
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 05:38 AM
Please share that script which is setting the Description which is iterating over
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader