Help with UI Action scripting

Abhijit Das7
Tera Expert

Hi Everyone,

 

I have created UI action knowledge article form. When I click on that UI Action then it should open dialog box with list of records from custom table. I click on any record then dialog box should destroy and there is reference field on knowledge article that should get populated. This reference field is not getting populated.

 

UI Action:

 

 

function openCustom() {

    var table = "x_custom_table"; // Custom table name
    var tableList = "x_custom_table_list"; //list of custom table

    var dialog = new GlideDialogForm("Table", tableList);
    dialog.setDialogHeight('800');
    dialog.setDialogWidth('800');
    dialog.setLoadCallback(populate);
    dialog.render();

    function populate(item) {
        var fields = ["x_model_name"];  //x_model_name is a string field on custom table form
        var msg = "";
        fields.forEach(function(field) {
            msg += item.getElementById(table + "." + field).value + "\n";
        });
alert(msg);
      var exName =  g_form.setValue("x_ref_name", msg);  // x_ref_name is reference field on kowledge article form.
alert(exName);
        if (item.getElementById('sys_uniqueValue').value)
            dialog.destroy();

    }
}

 

 

 

Please guide me how can I populate reference field. All functionalities are working in my requirement except reference field getting populated.

 

cc: @Ankur Bawiskar @kamlesh kjmar

 

 

Thanks in advance

1 ACCEPTED SOLUTION

@Abhijit Das7 

yes either use GlideAjax or query directly.

But this will help only if you have unique record for that field value

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

@Abhijit Das7 

alert(msg) shows sysId of selected record?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

alert(msg) shows the name of that record - for example if you look into screenshot of dialog window there is field call Experience Name - that is coming in alert(msg). Unfortunately sys_id is not coming. 

 

Thanks

@Abhijit Das7 

you can query the table with that field and get the sysId but that field should be unique

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

 

If I try to make it clear, you are saying to do GlideAjax to script include. And there I can do GlideRecord and get sys_id.

 

Thanks in advance

 

@Abhijit Das7 

yes either use GlideAjax or query directly.

But this will help only if you have unique record for that field value

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader