How to get username in latest additional comments

Sri56
Tera Contributor

Hi Team,

We are having requirement that we are having one field called add info (reference user field) so when there is an additional comment from this user we need to change the state to WIP.

currently i'm getting a latest comment in this format:

2022-04-27 09:21:27 - user1 (Additional comments)
tested ok

so here we need only user1 value to compare with add info field which we have created.

Please help with the code.

Thanks,

Sri

1 ACCEPTED SOLUTION

Hi,

update as this

var addinfousr = current.u_additional_information.getDisplayValue();
gs.log("additional user information:::"+addinfousr);
var com = current.comments.getJournalEntry(1);
if(com.indexOf(addinfousr) > -1)
{
    gs.log("inside the latest update from add info if statement:::");
    current.state='2';
    current.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Snehangshu Sark
Mega Guru

Hi there,

 

Try this, it's tested. 

var comm = gr.comments.getJournalEntry(1);  //get the latest comment // gr can be replaced based on your your script

var userName = comm.split('(Additional comments)\n')[0].split('-')[3];

 

Regards,

Snehangshu Sarkar

 

Please mark my answer as correct if it resolves your query.

 

Thanks, it perfectly gave the user name.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

can you share what script you tried?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I tried below script

business rules written on sc_task on after update

var addinfousr = current.u_additional_information.getDisplayValue();
gs.log("additional user information:::"+addinfousr);
var com = current.comments.getJournalEntry(1);
gs.log("latest comments:::"+com);
var userName = com.split('(Additional comments)\n')[0].split('-')[3];
gs.log("username from latest comments:::"+userName +addinfousr);
if(userName == addinfousr)
{
gs.log("inside the latest update from add info if statement:::");
current.state='2';
current.update();
}

every logs working except inside the if statement,

Please help with the condition

if(userName == addinfousr)

 

Please help!

 

Thanks,

Sri