- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 03:38 AM
var targetPrioTwo = new GlideRecord('x_327210_project_consultants') ;
targetPrioTwo.addQuery('currently_available',true);
targetPrioTwo.query();
while (targetPrioTwo.next()) {
targetPrioTwo.addQuery('qualification','=',current.required_requirement);
targetPrioTwo.query()
while (targetPrioTwo.next()){
workflow.scratchpad.prioTwo.push(target.name);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 05:29 PM
Hi Hilberto,
You can add an array variable and pass the values of it as scratchpad value.
Try this updated code.
var test_array = [];
var targetPrioTwo = new GlideRecord('x_327210_project_consultants') ;
targetPrioTwo.addQuery('currently_available',true);
targetPrioTwo.query();
while (targetPrioTwo.next()) {
test_array.push(target.name);
}
workflow.scratchpad.new_array = test_array;
Regards,
Raf

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 05:27 PM
Please fix your query to
workflow.scratchpad.prioTwo = [];
var targetPrioTwo = new GlideRecord('x_327210_project_consultants') ;
targetPrioTwo.addQuery('currently_available',true);
targetPrioTwo.addQuery('qualification',current.required_requirement);
targetPrioTwo.query();
while (targetPrioTwo.next()) {
workflow.scratchpad.prioTwo.push(targetPrioTwo.name+'');
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 05:29 PM
Where is your target variable declared?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 05:29 PM
Hi Hilberto,
You can add an array variable and pass the values of it as scratchpad value.
Try this updated code.
var test_array = [];
var targetPrioTwo = new GlideRecord('x_327210_project_consultants') ;
targetPrioTwo.addQuery('currently_available',true);
targetPrioTwo.query();
while (targetPrioTwo.next()) {
test_array.push(target.name);
}
workflow.scratchpad.new_array = test_array;
Regards,
Raf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 10:44 PM
Hello Hilberto,
you have written a perfect code. But you need to use toString if you are passing anything to array.push:
var targetPrioTwo = new GlideRecord('x_327210_project_consultants') ;
targetPrioTwo.addQuery('currently_available',true);
targetPrioTwo.query();
while (targetPrioTwo.next()) {
targetPrioTwo.addQuery('qualification','=',current.required_requirement);
targetPrioTwo.query()
while (targetPrioTwo.next()){
workflow.scratchpad.prioTwo.push(target.name.toString());
}
NOTE:
Whenever you're looping and pushing data directly from a query, you need tostring() it.
array.push(gr.sys_id.toString); OR array.push(gr.getValue('sys_id').toString);
And see if that helps. Whatever is causing this problem I've seen it hundreds of times. If you're looping and you're using an object, if you don't string it you may end up with a list of the same thing (or worse- if you're doing an update on this field, you'll find yourself updating the same record numerous times). I always make sure to toString() or format the object so ServiceNow treats the data separately.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade