- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 04:27 AM
Hi,
I am getting some list of ID's by querying a table, now i need to assign all those ID's to a list field.
Please let me know how can i achieve this.
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 05:38 AM
you need to do it like this
var arr = [];
var allChildRecords = new GlideRecord('sc_request');
allChildRecords.addQuery('parent', parentSysId);
allChildRecords.query();
while(allChildRecords.next()){
arr.push(allChildRecords.getValue('sys_id'));
}
current.list_field = arr.join(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 04:29 AM
Hi
A list field is just a comma separated string of sys_ids for records in the table which the list is pointing to.
So if you have your IDs in eg. an array you can say
current.list_field = array.join(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 04:33 AM
Hi Sk59,
If the field is belonging to the same table from which you have gathered the sys_id. You can simply set the field with that variable then.
say your sys_id are stored in var a, which was an array, you can use something like a.join(',');
then simply you can set the field to current.list_field=a; //server side, use g_form for client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 04:39 AM
var allChildRecords = new GlideRecord('sc_request');
allChildRecords.addQuery('parent', parentSysId);
allChildRecords.query();
while(allChildRecords.next()){
var ID = allChildRecords.u_id;
}
In the above code I am getting multiple id's in ID. I need to assign these ID's into a list field(say 'abc') in a different table (say change table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 04:46 AM
Hi Sk59,
I am skeptical about you getting the results like that. Please employ array to store sys_id.
Reference qualifier on catalog item using script include to exclude records dynamically deals with a similar issue, please refer to the answer made by chuck or the correct answer.
Dont forget to mark the answer correct or helpful,if it helps