How to get sys_id from a related list and populate it on a form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2015 02:02 PM
Hello. I have a Survey related List below my Incident and it shows the Survey sent out (survey_details) table. Can someone please advise how i can get the sys_id of the Survey that was sent out. Then take that sys id and populate it to a text field on the parent table. I tired about 50 different things. Can somone advise here basically I need a sys id from a related talist that only has one item...
var gr = new GlidRecord("task_survey");
//var result;
finding the Survey thats attached to this incident
gr.addQuery("task.sys_id", parent.sys_id);
gr.query();
while(gr.next()) {
//trying to fetch the sys id of the survey that was found
var result = gr.sys_id;
//trying to populate a reference field I have that references the task survey table from Incident
parent.u_survey = result;
//trying instead to populate a plain text field with the sys_id
parent.u_survey_sysid = result;
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2015 10:37 AM
Hello Bessam,
I'm glad that you got this working. The get is just a shorthand to retrieve one record. You could do the same with the standard query that you were running
var gr = new GlideRecord("task_survey");
gr.addQuery("task", current.sys_id);
gr.query();
if (gr.next(){
[Do Something]
}
The main difference is that the query can return more than one record. Ignore me if you are referring to the fields rather than the method
There should be this button in the bottom left of each post if you would like to mark the thread as complete:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 08:46 AM
What version are you on? Are you using the legacy survey or the new Assessment modules. If later, the instead of querying "task_survey" table, use "asmt_assessment_instance".
var gr = new GlidRecord("asmt_assessment_instance");
//var result;
finding the Survey thats attached to this incident
gr.addQuery("trigger_id", parent.sys_id);
gr.query();
while(gr.next()) {
//trying to fetch the sys id of the survey that was found
var result = gr.sys_id;
//trying to populate a reference field I have that references the task survey table from Incident
parent.u_survey = result;
//trying instead to populate a plain text field with the sys_id
parent.u_survey_sysid = result;
Regards,
Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 10:46 AM
It is a legacy Survey