Is there any alternative for current.update() method in servicenow?

Pavan Kumar BV
Kilo Expert

Hello Everyone,

I have a business scenario where if i create an incident in InstanceA, it should create an incident in InstanceB. Also, any updates made to an incident in InstanceA should also reflect in InstanceB. I have configured a REST message and also a Business Rule. The problem is, i have used current.update() at the end of my BR and its causing performance issues while executing insert/update actions. Is there any alternative to this method to achieve back my performance?

Below is my BR

(function executeRule(current, previous) {

 var r = new sn_ws.RESTMessageV2('ABC to MSP Rest Message ', 'ABC to MSP');
 r.setStringParameterNoEscape('u_short_description', current.short_description);
 r.setStringParameterNoEscape('u_impact', current.impact);
 r.setStringParameterNoEscape('u_configuration_item', current.cmdb_ci);
 r.setStringParameterNoEscape('u_incnumber_abc', current.number);
 r.setStringParameterNoEscape('u_subcategory', current.subcategory);
 r.setStringParameterNoEscape('u_caller', current.caller_id);
 r.setStringParameterNoEscape('u_sysid_abc', current.sys_id);
 r.setStringParameterNoEscape('u_urgency', current.urgency);
 r.setStringParameterNoEscape('u_category', current.category);
 r.setStringParameterNoEscape('u_description', current.description);

 var response = r.execute();
 var responseBody = response.getBody();
 var parsed_response=JSON.parse(responseBody);
 var id =parsed_response.result[0].sys_id;
 var id1 =parsed_response.result[0].display_value;
 current.u_msp_incident_sysid = id;
 current.u_msp_incident_number = id1;
 current.update();
 var httpStatus = response.getStatusCode();

1 ACCEPTED SOLUTION

Pavan Kumar BV
Kilo Expert

I have figured out the problem for this unexpected behavior. It was in my HTTP method where i have given an extra space in one of the variable declaration. Once i rectified that everything is working as expected.

Thanks everyone for your response.

View solution in original post

13 REPLIES 13

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you explain what you mean by performance issues? Can it already be that this BR is executed on update for example, and you just need to add conditions? Also when is this BR running? Did you try async?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Thanks for your response.

By performance i mean its taking lot of time for the insert/update operation. Whenever i create an incident in Instance A, its taking almost 60-75 seconds to create it in Instance B. Also any incident updates from Instance B to Instance A is taking the same time. The update behavior is also not as expected(extra spaces are getting added in the short description). Below snaps will give you some more insights.

Below is my XYZ instance where i update the short description as "VPN issue" for an Incident. But after the end of transaction below is what i see(Extra spaces at the start of my short description and the text is getting disappeared in the end. Its updated only till "VPN I")

find_real_file.png

Now, if i check the corresponding ticket(INC0010070)) in the other instance, below is what i see(Extra spaces again).

 

find_real_file.png

I heard that current.update() is not a best practice to use. could this be the issue for the delayed response and unexpected behavior.

 

Yes I understand. Though, how do the conditions on your Business Rule look like? When does the Business Rule run? Etc..

I mean, if this is a before Business Rule, the current.update() isn't even needed. If this is an after Business Rule, might this Business Rule be triggering itself again? Etc..

So how does your Business Rule look like. Not the code, the triggers, conditions, etc..

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Below are my BR conditions.

InstanceA :

Insert and Update options checked + Priority is either 1 or 2 + assignment group is "xxxxxx"

The BR mentioned in the question is the once corresponding to this instance.

Instance B:

Update checked and there are not other conditions specified. Below is my BR in this instance.

(function executeRule(current, previous /*null when async*/) {

var r = new sn_ws.RESTMessageV2('MSP to ABC Rest', 'MSP to ABC');
r.setStringParameterNoEscape('Caller',current.caller_id);
r.setStringParameterNoEscape('ConfigurationItem',current.cmdb_ci);
r.setStringParameterNoEscape('Subcategory',current.subcategory);
r.setStringParameterNoEscape('Urgency',current.urgency);
r.setStringParameterNoEscape('Impact',current.impact);
r.setStringParameterNoEscape('Category',current.category);
r.setStringParameterNoEscape('State',current.state);
r.setStringParameterNoEscape('u_client_incident_number',current.u_client_incident_number);
r.setStringParameterNoEscape('Short Description',current.short_description);
r.setStringParameterNoEscape('u_client_incident_sysid',current.u_client_incident_sysid);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

})(current, previous);