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

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhijit Das7 

please share some screenshots.

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

Hi @Ankur Bawiskar 

 

This is the UI Action :

instruct1.jpg

2. The above UI Action is placed on knowledge article form:

instruct 2.jpg

3. When clicked on this UI action, it should open a dialog window with list of records from custom table:

instruct 3.jpg

4. Once the dialog window open, when I click on any record then dialog window should destroy and one reference field which is referenced to that custom table should get populated. For me that field is not getting populated.

instruct 4.jpg

 

Note: Basically we want this UI action to work similarly as how look up works for reference field. We cannot use look up function because this reference field will be hidden on form using UI Policy. In order to populate this Reference field we are using UI Action. 

 

Thanks in advance

@Abhijit Das7 

are you able to detect the click of any record somehow in that UI page? If yes then only you will be able to know which record was clicked?

Since the whole purpose is to select the reference record and I believe the reference field is also referring to same custom table why not show that field and allow user to select the record directly? anyhow you are showing the list of records similar to how lookup icon works

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

Hi @Ankur Bawiskar 

 

If you see my UI Action code - there I have placed two alerts in that = alert(msg) and alert(exName).

So , alert(msg) displays the name of the record which I clicked where as second alert(exName) returns undefined. 

 

And we cannot display this reference field. According to client, it should remain hidden to customer. That's why we are going with UI Action approach. If we were allowed to show that reference our work would have become very easy but unfortunately we have to hide it.

 

Thanks in advance.