- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 10:02 PM
hi members,
I have one br on incident table where i have custom fields in which am trying to update one of them below is the eg:
var fieldname1 = "hello world";
current.variables.fieldname2 = fieldname1;
current.update()
but the above code its not doing anything but i can see in logs if i try to print above value
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 10:29 PM
Hi,
Few things to inform/check
1) Avoid current.update() in Business rule as it would lead to recursion and is not recommended
2) Also what you want to update? Is it a variable on the incident form or a field
Please use after insert/update BR and sample script below
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var fieldname1 = "hello world";
var rec = new GlideRecord('incident');
rec.get(current.sys_id);
// if you want to update some variable; give proper variable name
rec.variables.fieldname2 = fieldname1;
rec.update();
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 10:25 PM
Hi,
It is not best practice to write "current.update()" method in Business rule (Server code).
You can glide a table then update.
For example:
var gr=new GlideRecord(<tablename>); //Creating object to the table(just like creating a link to the table)
gr.addquery("<fieldname>","<fieldvalue>"); // the condition to pick only selected rows
gr.query(); //Execute the command
while(gr.next()) //this will go through each of the records which are retrieved by the query
{
gr.<fieldname>="<value>"; // you can update any field value of each of the record here
gr.update(); // this will update the field value of the particular record.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 10:29 PM
Hi,
Few things to inform/check
1) Avoid current.update() in Business rule as it would lead to recursion and is not recommended
2) Also what you want to update? Is it a variable on the incident form or a field
Please use after insert/update BR and sample script below
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var fieldname1 = "hello world";
var rec = new GlideRecord('incident');
rec.get(current.sys_id);
// if you want to update some variable; give proper variable name
rec.variables.fieldname2 = fieldname1;
rec.update();
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader