- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 06:22 AM
Hi
I am having a tricky requirement for service catalog. Can you help me to start with the logic and guide me in the right path.
I am having two fields on a service catalog form. Fields are (User name & department name).
Both fields are of type list_collector and variable attributes as glide_list.
User can select multiple values on the form for the fields ( User name & department name).
So the exact requirement here is :
Upon submission of a request , the values(data) selected for the fields ( User name & department name) should be inserted in one of the target table( for example table name is u_abc) in ServiceNow.
The target table is having three fields as (FieldA, FieldB & FieldC)
1). FieldA is a type of reference field.
2). FieldB is also a type of reference field.
3). FieldC is a type of choice field. ( choices as type-user, type-department)
Now after submission of a service request , data of a field "User name" (type of list_collector on a form) should be added in a FieldA (type of a reference field) in the table.
Data of a field "department name" (type of list_collector on a form) should be added in a FieldB (type of a reference field) in the table.
Let me take an example for the scenario.
If a user is selecting 2 values for field "User name" (type of list_collector on a form) and 3 values for field "department name" (type of list_collector on a form)
then total 5 entries should be inserted in the target table in ServiceNow
"User name" -> FieldA ( two entries ) and this third field "FieldC " will set as "type-user" for two entries (in the table)
"department name" -> FieldB (three entries) and this third field "FieldC " will set as type-department for three entries (in the table)
I am able to implement the logic for the same and it is working fine but having addition requirement in this.
If the requested values are already available in the target table , then we do not need to insert the data. If it is new only then we need to insert.
for eg. If user is selecting 3 values from a glide_list on a catalog form and out of 3 values 1 is already available in the target table , then we need to insert only two value that are new.
Pls help me to extend my logic for this addition requirement.
var uList = objRITM.variables.user_list.toString();
var uList _split = uList .split(',');
if (uList _split.length> 0) {
for (var i = 0; i < uList _split.length; i++) {
var gr = new GlideRecord('table_name');
gr.initialize();
gr.user_field = uList _split[i];
gr.choice_field = type-user;
gr.insert();
}
}
Thanks !!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 07:03 AM
Hi,
something like this
var uList = objRITM.variables.user_list.toString().split(',');
for (var i = 0; i < uList.length; i++) {
var gr = new GlideRecord('table_name');
gr.addQuery('user_field', uList[i]); // query with user_field to check if record is already present
gr.query();
if(!gr.hasNext()){
gr.initialize();
gr.user_field = uList[i];
gr.choice_field = type-user;
gr.insert();
}
}
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
03-21-2022 07:03 AM
Hi,
something like this
var uList = objRITM.variables.user_list.toString().split(',');
for (var i = 0; i < uList.length; i++) {
var gr = new GlideRecord('table_name');
gr.addQuery('user_field', uList[i]); // query with user_field to check if record is already present
gr.query();
if(!gr.hasNext()){
gr.initialize();
gr.user_field = uList[i];
gr.choice_field = type-user;
gr.insert();
}
}
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
03-21-2022 07:19 AM
Thanks Ankur let me try this and will let you know the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 12:40 AM
Hi
Do we not required the if condition in this case , as earlier I have applied this if condition
if (uList.length> 0){
// here for loop condition
}
Pls let me know..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 12:41 AM
Hi
Do we not required the if condition in this case , as earlier I have applied this if condition
if (uList.length> 0){
// here for loop condition
}
Pls let me know..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 01:07 AM
Thanks a lot Ankur , the solution worked..
Thanks !!