Work notes field updates twice?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2015 10:21 PM
Trying to change the 16 digit numbers typed in work notes to display only the last four digits in the activity log. Tested the code working fine with Description field. But when trying it in work notes and additional comments field(Journal Field), i am getting the initial value which is typed in the work notes along with the converted value in the activity log.
For Example If i type 1111 2222 3333 4444 in work notes - expected output in activity log is 4444 but in activity log, i am getting the 4444 along with the typed value 1111 2222 3333 4444.
I have tried two type of codes, none fixed the issue.
Code : 1
============
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var str = current.work_notes;
var res = str.match(/(\b\d{16}\b|\b(\d{4}( \d{4}){3})\b)/g);
//gs.addInfoMessage("first"+str);
//gs.addInfoMessage("second"+res.length);
for (var i=0; i<res.length ; i++)
{
var lastFourStr = res[i].substring(res[i].length-4, res[i].length);
str = str.replace(res[i], "#"+lastFourStr);
}
current.work_notes = str;
gs.addInfoMessage("last"+str);
}
Code :2
========
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var qry=new GlideRecord('sys_journal_field');
qry.addEncodedQuery('element=work_notes^element_id='+current.sys_id);
qry.orderByDesc('sys_created_on');
qry.query();
if(qry.next())
{
var str = qry.value;
var res = str.match(/(\b\d{16}\b|\b(\d{4}( \d{4}){3})\b)/g);
for (var i=0; i<res.length ; i++)
{
var lastFourStr = res[i].substring(res[i].length-4, res[i].length);
str = str.replace(res[i], "#"+lastFourStr);
}
qry.value = str;
gs.addInfoMessage("last"+str);
qry.update();
}
}
Note: User may send message that contains 16 digit number via inbound mail to update on the record or may paste it manually in work notes. So need a solution for this. Any help in this regards, will be highly appreciated.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2015 06:28 AM
work notes and activity log are stored in the sys_journal_field table. Maybe you have to place business rules on that table to make it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2015 11:32 PM
It is happening because of using update function after business rule. And check the same for ur table.I meant if any other business rule with update() in your table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 09:00 AM
Hello
I have a question please
in the form incident the comments populate the work Notes
how, with a client script or BR?
thanks