Risk assessment button is not working and data is not populating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 12:35 PM
We have Assessment table(assessment).
In change table(change_table) we have reference field which is (assessment_instance) as it is referring to assessment table.
Now we have main table which is task table in that I have created a UI action with below code.When we click on UI Action it should pop up and the data needs to be visible but it is not working as expected.
Please correct me where I have made mistake.
UI Action :
function showResponse() {
var id = g_form.getUniqueValue();
var type = g_form.getValue('metric_type');
var a = g_form.getValue('number');
var inc = new GlideRecord("change_table");
inc.addQuery("name", "CONTAINS", a);
inc.query();
while (inc.next()) {
var b = inc.getValue("assessment_instance");
}
var ass = new GlideRecord("assessment");
ass.addQuery("number", b);
ass.query();
while (ass.next()) {
var c = ass.getValue("sys_id");
}
var url = 'assessment_take.do?sysparm_assessable_sysid=' + b + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
var d = new GlideOverlay({
title: getMessage("User's Response"),
iframe: url,
width: '80%',
height: '100%',
onAfterLoad: function() {
var iframe = d.getIFrameElement();
setTimeout(function() {
iframe.height = parseInt(iframe.height) + 1;
}, 0);
}
});
d.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 05:38 PM
Declare variable 'b' outside of the "where" loop, so it is valid later. Update 'b' inside the loop. Same for variable 'c', but I don't see that referenced later in the script. Besides that, others can comment on how you popup some data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:26 AM
Thanks for the reply Bert.
I have tried as you suggested but bad luck its not working.Below is the modified code.
UI Action :
function showResponse() {
var id = g_form.getUniqueValue();
var type = g_form.getValue('metric_type');
var a = g_form.getValue('number');
var b = ' ';
var c = ' ';
var inc = new GlideRecord("change_table");
inc.addQuery("name", "CONTAINS", a);
inc.query();
while (inc.next()) {
b = inc.getReference("assessment_instance");
}
var ass = new GlideRecord("assessment");
ass.addQuery("number", b);
ass.query();
while (ass.next()) {
c = ass.getValue("sys_id");
}
var url = 'assessment_take.do?sysparm_assessable_sysid=' + b + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
var d = new GlideOverlay({
title: getMessage("User's Response"),
iframe: url,
width: '80%',
height: '100%',
onAfterLoad: function() {
var iframe = d.getIFrameElement();
setTimeout(function() {
iframe.height = parseInt(iframe.height) + 1;
}, 0);
}
});
d.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 03:33 PM - edited 12-06-2023 05:16 PM
Some comments on the GlideRecord portion of you code.
1. I don't have a table named 'change_table' or 'assessment' in my instance, so I don't know what fields are there.
2. since you have while loops for processing records, b and c will be from the last record returned.
3. what table is the UI action defined on?
I have no comment on the code after you set 'url'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:45 AM
Sorry @Pravallika Rach
I am not a coder here, so cant help much on code correction.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************