On before business rule on comments

diogo_ramos
Mega Expert

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 ?

1 ACCEPTED SOLUTION

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:



Screen Shot 2017-10-02 at 2.34.49 PM.png



Works for me at least.


View solution in original post

14 REPLIES 14

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Have you tried printing "merged" variable?



gs.log(merged)



I believe "merged" variable might hold an object rather than a simple string.


Can you try this:



var comments_added = current.comments.toString();  


var merged = comments_added   + "SAMPLE TEXT";



Also it's a before update business rule? What order is it? Must be last one I would expect.


Harsh Vardhan
Giga Patron

Hi Diogo,



if i am not wrong you want to update the comment. if yes



try with script below.



current.comments='hello harsh';






find_real_file.png


souren0071
Tera Expert

Could you please tell me what is the use of   last line of comments?



cur}})(current, previous);)(current, previous);rent.comments = merged;



Regards,


Souren


That was an error pasting It, it's correct in the code, sergiu.panaite I've tried with tostring I get the same result (order is 1)comments.PNG


BR :


BR.PNG



I'm assuming if this won't work I need to get a client script going on submit maybe.