How to write a script for getting the record info in the UI Action

Pravallika Rach
Tera Contributor

When I run in background script it is working as expected you can refer to "Example line" as i have hardcode the query but when I try in UI action it is working as expected.I clearly understood that I have made a mistake in gliderecord query so please guide me to resolve the issue.

 

 

 

function showResponse() {
    var type = g_form.getValue('metric_type');
    var a = g_form.getValue('task_number'); //task_number = Integer type(INC0055358)
    var b = ' ';

    var inc = new GlideRecord("change_table");
    inc.addQuery("name", "CONTAINS", 'a'); //name is string type(Task: INC0055358 requesting Deferred, Awaiting Maintenance) , where as "a = INC0055358"
//Example : inc.addEncodedQuery("name" , "CONTAINS" , "INC0055358");
    inc.query();
    if (inc.next()) {
         b = inc.assessment_instance; // reference field
    }
    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();
}

 

1 REPLY 1

Ethan Davies
Mega Sage
Mega Sage

Since you are combining Client-side and Server-side code in your UI Action you need to arrange your code a little differently. Take a look at this article by ServiceNow Guru that covers this topic well, look at the Reopen Incident example.

 

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/