- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 12:59 PM
Hi Everyone.
This is my first time posting, so apologies if I don't include all the proper information.
We have a service catalog option that I created for requesting a website to be set up. Throughout the workflow 4 different tasks get created (linearly). The catch here is that each task needs to have a different watch list based on what the submitter enters. For example, we request to know the programmers name, projector director, etc. These variables are set up as reference fields to the user table. I tried to search through the site before submitting and I found a few useful things, but I am still unable to get this to work correctly.
To try to accomplish this I have set up a script on the task:
var user_array = [];
var users = new GlideRecord('sys_user');
users.addQuery('name',current.webreq_techcontact);
users.query();
while(users.next()){
user_array.push(users.sys_id.toSting());
}
if(JSUtil.notNil(current.watch_list)){
sc_req_item = current.watch_list + ',' + user_array.toString();
}else{
sc_req_item = user_array.toString();
}
Just a couple more notes, the webreq_techcontact is my variable on the form. We are also trying to set the request item watch list instead of the task one because our users cannot view tasks and we're trying to avoid confusion. Any help would be appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2015 10:47 AM
I solved this after a suggestion from Michael that is posted below.
I actually found out I did not need to run any queries, as the user was already giving me the value that I needed. I just added the variable to an array and then added the watch_list field from the form onto the array, after checking to see if it was empty. Here is the final code I ended up using:
var user_array = [];
user_array.push(current.variables.webreq_techcontact);
if(JSUtil.notNil(current.variables.watch_list)){
user_array.push(current.variables.watch_list);
current.watch_list = user_array.toString();
}else{
current.watch_list = user_array.toString();
}
Thank you to everyone who responded and provided me with suggestions! I need to remember not to over complicate things
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 01:05 PM
Hi Jerry,
I see error in line 3. Please replace current.webreq_techcontact with current.variables.webreq_techcontact and check the result.
var user_array = [];
var users = new GlideRecord('sys_user');
users.addQuery('name',current.variables.webreq_techcontact);
users.query();
while(users.next()){
user_array.push(users.sys_id.toSting());
}
if(JSUtil.notNil(current.watch_list)){
sc_req_item = current.watch_list + ',' + user_array.toString();
}else{
sc_req_item = user_array.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 06:02 AM
Hi Pradeep,
Thank you for your quick response! I made the changes as suggested and still no luck. I found another error that I fixed too. Here is what the updated code is:
var user_array = [];
var users = new GlideRecord('sys_user');
users.addQuery('name',current.variables.webreq_techcontact);
users.query();
while(users.next()){
user_array.push(users.sys_id.toString());
}
if(JSUtil.notNil(current.variables.watch_list)){
sc_req_item.watch_list = current.variables.watch_list + ',' + user_array.toString();
}else{
sc_req_item.watch_list = user_array.toString();
}
Any other suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 11:36 PM
In line 8 try to not convert sys_id to string and see if it works that way
And if it does dot help - try to change check condition for if starement on something like .... watch_list != ''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2015 10:47 AM
I solved this after a suggestion from Michael that is posted below.
I actually found out I did not need to run any queries, as the user was already giving me the value that I needed. I just added the variable to an array and then added the watch_list field from the form onto the array, after checking to see if it was empty. Here is the final code I ended up using:
var user_array = [];
user_array.push(current.variables.webreq_techcontact);
if(JSUtil.notNil(current.variables.watch_list)){
user_array.push(current.variables.watch_list);
current.watch_list = user_array.toString();
}else{
current.watch_list = user_array.toString();
}
Thank you to everyone who responded and provided me with suggestions! I need to remember not to over complicate things
