- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 07:09 AM
All, I would like to parse text that is within the description field. I have used regex before but I am a little stuck on how to parse this out.
My string is below and what is in bold should be removed. I only want the words 'long description' to display in this field. Is this possible?
NEW_CALL_REF:7fe4cf7bdb53cb404ad038f0ad961926 New Call DESC: Long Description NEW CALL SHORT_DESC: Short Description
I created a business rule to run on Before and I have so far is below. Any help???
// Add your code here
var descrip = current.getValue('description');
var regex = /New Call DESC:.*/g;
var str = descrip; // Example `NEW_CALL_REF:7fe4cf7bdb53cb404ad038f0ad961926 New Call DESC: Long Description NEW CALL SHORT_DESC: Short Description`;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 08:18 AM
Here is an example I was doing via background script:
var string = "NEW_CALL_REF:7fe4cf7bdb53cb404ad038f0ad961926 New Call DESC: Long Description NEW CALL SHORT_DESC: Short Description";
var key1 = "New Call DESC:";
var key2 = "NEW CALL SHORT_DESC:";
var key1Index = string.indexOf(key1) + key1.length;
var key2Index = string.indexOf(key2);
var desc = string.substring(key1Index, key2Index).trim();
gs.print("'" + desc + "'");
Output is:
*** Script: 'Long Description'
I had single quotes on it to make sure the trim() function removed leading and trailing spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 07:22 AM
I assume this is coming from an external source? Do you have any opportunity to edit what comes over? Parsing is very difficult unless there are standards in place. For example I see NEW and New and NEW_CALL_REF (underscores) and New Call DESC (spaces). It would be ideal if you could put a | or ^ or something between each field or even a line break.
If not you could use the javascript substr function to look for "New Call DESC" and grab that text till "NEW CALL SHORT_DESC" assuming these always are in this order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 08:03 AM
Hi Michael,
Yes it will alway come in that way into the description. One being the obvious that it will be different text, but definitely the same order.
I was following around and was able to get this much taken off by
var indx2 = full_text.indexOf('New Call DESC');
var desc = full_text.substring(indx2,full_text.length);
current.description = desc;
my output is:
New Call DESC: Long Description NEW CALL SHORT_DESC: Short Description
I am getting close, but how do I get the above removed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 08:18 AM
Here is an example I was doing via background script:
var string = "NEW_CALL_REF:7fe4cf7bdb53cb404ad038f0ad961926 New Call DESC: Long Description NEW CALL SHORT_DESC: Short Description";
var key1 = "New Call DESC:";
var key2 = "NEW CALL SHORT_DESC:";
var key1Index = string.indexOf(key1) + key1.length;
var key2Index = string.indexOf(key2);
var desc = string.substring(key1Index, key2Index).trim();
gs.print("'" + desc + "'");
Output is:
*** Script: 'Long Description'
I had single quotes on it to make sure the trim() function removed leading and trailing spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 09:46 AM
thanks michael
It worked. I have marked your answer as correct for others.