- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 04:26 AM
Hi Team,
I have two tables,
1.Incident
2.Personal incident,
Below are the screenshots of table list view.
Incident table: Here "Incident IDs" field having multiple incidents
Personal Incident table:Here having two fields(Incident number, Comments)
Requirement:
Fetch all the comments from Personal incident table to Incident table(Field-name:Personal comments) with respective Incident IDs field from incident table.
Ex:Incident Id's :INC0009005,INC0009009, So in Personal comments should have two comments :09876,hello
Note:Incident fields are string type in both tables.
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:23 AM
Hi,
You can write before Update/insert business rule on Incident table and use below script logic:
var comm =[];
var perInc = new GlideRecord('u_personal_incident');
perInc.addQuery('u_incident_number','IN',current.u_incident_ids.toSTring());
perInc.query();
while(perInc.next()){
comm.push(perInc.u_comments.toSTring());
}
current.u_personal_comments = comm.toString();
Please make required changes in above script as per your configuration.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:09 AM
can u share the code u have tried so far ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:23 AM
Hi Ravi,
Here is my code
var inc=GlideRecord('incident');
inc.addNotNullQuery('u_incident_ids');
inc.query();
while(inc.next()){
var perinc=GlideRecord('u_personal_incidents');
perinc.addEncodedQuery('u_incident_numberIN'+inc.u_incident_ids);
perinc.query();
var arr=[];
var j = 0;
while(perinc.next()){
arr[j]=perinc.u_comments.toString();
// gs.log(arr[j].length);
gs.log(arr[j]);
j++;
//inc.u_personal_inc=arr[j];
//inc.update();
}
}
Output:
*** Script: hi
*** Script: 123456
*** Script: 09876
*** Script: hello
Expected Output:
*** Script: hi,123456
*** Script: 09876,hello

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:26 AM
Hi,
Try below:
var inc=GlideRecord('incident');
inc.addNotNullQuery('u_incident_ids');
inc.query();
while(inc.next()){
var perinc=GlideRecord('u_personal_incidents');
perinc.addEncodedQuery('u_incident_numberIN'+inc.u_incident_ids.toString());
perinc.query();
var arr=[];
while(perinc.next()){
arr.push(perinc.u_comments.toString());
// gs.log(arr[j].length);
}
gs.log(arr.toString());
//inc.u_personal_inc=arr.toString();
//inc.update();
}
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:30 AM
If you want to use your own logic then try below:
var inc=GlideRecord('incident');
inc.addNotNullQuery('u_incident_ids');
inc.query();
while(inc.next()){
var perinc=GlideRecord('u_personal_incidents');
perinc.addEncodedQuery('u_incident_numberIN'+inc.u_incident_ids);
perinc.query();
var arr=[];
var j = 0;
while(perinc.next()){
arr[j]=perinc.u_comments.toString();
j++;
}
gs.log(arr.toString());
//inc.u_personal_inc=arr.toString();
//inc.update();
}
Thanks,
Anil Lande
Thanks
Anil Lande