- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 02:14 AM
Hi All!
I am trying to get the incident description field which contains
{"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}
When i do the below background script,
var string = '{"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}';
if (string.indexOf('{"Impact":"SERVICES"') > -1) {
var body = string.split('href=\"'); //find to spilt
body = body[1].split('\">Open'); //end split
body = body[0].toString(); // This is the string
gs.print(body);
}
And the result is good
However, if i put this in a Business before rule:
(function executeRule(current, previous /*null when async*/ ) {
//incident description is {"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}
var string = current.description;
if (string.indexOf('{"Impact":"SERVICES"') > -1) {
var body = string.split('href=\"'); //find to spilt
body = body[1].split('\">Open'); //end split
body = body[0].toString(); // This is the string
gs.log(body, 'test');
})(current, previous);
However the logs shows that the string is not spited. I have tried to do var string = current.description.toString(); but doesnt help as well.
Anyone know where i have done wrong?
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 03:10 AM
Hi,
This issue is due to using the backslash character (\) while doing the split.
Try below code, its working for me.
Background Script -
var str = '{"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}';
var t = str.split("=");
var p = t[2].split('"');
gs.info(p[1]);
//Output
//*** Script: http://www.google.com
Business Rule -
(function executeRule(current, previous /*null when async*/ ) {
var desc = current.short_description;
if (desc.indexOf('{"Impact":"SERVICES"') > -1) {
var t = desc.split("=");
var p = t[2].split('"');
gs.log(p[1],'TEST123');
gs.log('Body = '+body,'TEST123');
}
})(current, previous);
Regards,
Sourabh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 03:10 AM
Hi,
This issue is due to using the backslash character (\) while doing the split.
Try below code, its working for me.
Background Script -
var str = '{"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}';
var t = str.split("=");
var p = t[2].split('"');
gs.info(p[1]);
//Output
//*** Script: http://www.google.com
Business Rule -
(function executeRule(current, previous /*null when async*/ ) {
var desc = current.short_description;
if (desc.indexOf('{"Impact":"SERVICES"') > -1) {
var t = desc.split("=");
var p = t[2].split('"');
gs.log(p[1],'TEST123');
gs.log('Body = '+body,'TEST123');
}
})(current, previous);
Regards,
Sourabh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 04:11 AM
Hi Max,
Try below code it's working for me, created after insert/update BR on Incident
(function executeRule(current, previous /*null when async*/ ) {
// var string = '{"Impact":"SERVICES",<a target=\"_blank\" href=\"http://www.google.com\">Open in Browser</a></p>","ProblemID":"P-1234"}';
var string = current.getValue('description');
if (string.indexOf('{"Impact":"SERVICES"') > -1) {
var matches = string.match(/\bhttps?:\/\/\S+/gi); // prints http://www.google.com\">Open
var body = matches.toString();
body = body.replace('">Open', ''); // prints http://www.google.com\
}
gs.info("Output Value is : " + body);
})(current, previous);
Output :
Kindly mark correct and helpful if applicable