Update description with caller name

Ajitsure
Tera Contributor

Requirement : Description needs to be updated as caller name after update using business rule.

 

I have tried below code but its not working.

 

var gr = new GlideRecord('incident');
gr.addQuery('caller_id.name',current.caller_id.name);
gr.addQuery('description',current.description);
gr.query();
while (gr.next())
{
return current.description=current.caller_id.name;
}

7 REPLIES 7

Okay.

Then use below

current.description = current.caller_id.name;
current.update();

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Rahul RJ
Giga Sage
Giga Sage

Hi Ajitsure,

You can write the business rule after the update 

 

 current.description=current.caller_id.name;
current.setWorkflow(false); //to avoid recursion
current.update();

Please mark my response as Correct based on Impact.

 

 

 

Jochen Geist
ServiceNow Employee
ServiceNow Employee

From a ServiceNow standpoint, I can only strongly advise against setting this up as an on after Business Rule and using current.update()

You can find detailed information on Now Support about what issues this will cause. 

 

The first step would be to understand why the name should be copied to the description. The name is already stored in sys_user and you can easily dotwalk there during filtering or reporting.

 

If there is a clear business requirement to do so, you won't need to write a single line of code to achieve this.

Just create a Flow that reacts on Caller changes;

JochenGeist_0-1672325162172.png

and then update the Incident:

JochenGeist_1-1672325189617.png