- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 01:47 AM
I have an on Before insert BR on the incident table that suppose to populate the assignment group field. Even though Im getting the log 'TRUE', the assignment group is not populated and instead Im getting an empty value inside the assignment group field. I checked and there is no BR that conflict with this BR. What am I doing wrong?
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var loc = current.location;
var gr = new GlideRecord('cmn_location');
gr.addEncodedQuery('sys_id='+loc+'^u_assignment_groupISNOTEMPTY');
gr.query();
if(gr.hasNext()){
gs.log('TRUE');
current.assignment_group = gr.u_assignment_group;
}
else{
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:09 AM
hasNext() either returns true or false while next() will actually iterate to the record.
try updating the code as:
gr.next()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:29 AM
@Alon Grod This script which i have provided that is also same. it is replaced with gr.next().
Please check it once.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:01 AM
if it has value then you should be able to print it?
did you check the XML of that record and it has value in it?
share screenshot of that record ?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:05 AM
@Ankur Bawiskar i meant that it has value in it in the cmn_location table.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var loc = current.location;
var gr = new GlideRecord('cmn_location');
gr.addEncodedQuery('sys_id='+loc+'^u_assignment_groupISNOTEMPTY');
gr.query();
if(gr.hasNext()){
gs.log('TRUE');
gs.log(gr.u_assignment_group);
current.assignment_group = gr.u_assignment_group;
}
else{
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:08 AM
is the script running in admin session?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:12 AM
you need not query since location is already reference field
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var group = current.location.u_assignment_group;
if(group)
current.assignment_group = group;
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader