- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 04:09 AM
Hi guys I currently have a problem, when I write a comment and I have a before business rule (comment changes), and I want to edit what was wrote in the comment field, when the business rule runs it duplicates the information as you can see:
Business Rule Conditions : Comments changes
(function executeRule(current, previous /*null when async*/) {
var comments_added = current.comments;
var merged = comments_added + "SAMPLE TEXT";
current.comments = merged;
})(current, previous);
Do you guys have any idea how can I changed the comment added to include more test ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:34 AM
So what is happening is that "comments" on Task table and it's extensions is a special one, it's not really a field, but part of a formatter. So, playing with the business rule here is not the right way, as the comments update is actually doing an insert into the sys_journal_field and sys_audit. So if you would like a business rule, it should have been one on the sys_journal_field before insert. But even so, I would not recommend going that far.
What if you try a before onSubmit client script like:
Works for me at least.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:02 AM
You're right Diogo, as I am able to reproduce this on OOB Jakarta instance. Give me some time so I can dig in to understand why this is happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:34 AM
So what is happening is that "comments" on Task table and it's extensions is a special one, it's not really a field, but part of a formatter. So, playing with the business rule here is not the right way, as the comments update is actually doing an insert into the sys_journal_field and sys_audit. So if you would like a business rule, it should have been one on the sys_journal_field before insert. But even so, I would not recommend going that far.
What if you try a before onSubmit client script like:
Works for me at least.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:40 AM
Thanks a lot for your investigation Sergiu, I thought about the same client script idea and I think it's the way we going to do it.
Cheers,
Diogo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 09:09 AM
If anyone is interested this is how I did it using a simple script:
function onSubmit() {
//Type appropriate comment here, and begin script below
function getSignature() {
var ga = new GlideAjax('getMySignature');
ga.addParam('sysparm_name','getMySignature');
ga.addParam('sysparm_user_id',g_user.userID);
ga.getXMLWait();
return ga.getAnswer(); // synchronous call wait until we got the value then proceed with the update
}
var comment = g_form.getValue("comments");
if (comment != "")
g_form.setValue("comments", comment + "\n\n" + getSignature());
}
Cheers
Diogo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 12:28 PM
The onSubmit() approach doesn't seem to work when comments are posted by clicking 'Post' button in the Journal section, not by clicking Update / Save on the form. Can anyone think of a way to modify the comments when user clicks on 'Post' button without writing a Before Business Rule on sys_journal_field ?