How to pass a list value to another list in UI Policy

ryo200
Tera Contributor

Hi,

Reference the record name of table 1 in table 2's form. I want to use it to query and add the values from the list in table 1 to the list in table 2.
but i can't do this.
Is-he possible to do this ?

 

Tabale1
name:table1_list_name Type:string
name:table1_list Type:list Reference:sys_user

 

Table2
name:table1_list_name2 Type:string
name:table2_list Type:list Reference:sys_user

 

UIPoricy
Conditon
tabale1_list_name2 is not null.

True
function onCondition() {
var userList = new GlideRecord('table1');
var user_array = [];
userList.addQuery('table1_list_name','=',current.table1_list_name2);
userList.query();
user_array.push(userList.table1_list.toSting());
current.table2list = user_array;
}

False
function onCondition() {
var user_array = [];
current.tabele2_list = user_array;
}


Thank you.

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@ryo200 Since the UI Policy executes at the client side, you should use GlideAjax, instead of a GlideRecord call.

Ram050670
Tera Guru

@ryo200 i would suggest to use client side onload or on change based on requirement and use Script include and call that with glide

 

----------------Script include---------------------

getUserDetails: function() {

var id = this.getParameter('sysparm_userID');
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', id);
grUser.query();

var usrobj = {};
while (grUser.next()) {
usrobj.email = grUser.name.toString();
}

return JSON.stringify(usrobj);

},

 

 

Client script:

-------------------------------------ON LOAD-----------------------------

function onLoad() {
//Type appropriate comment here, and begin script below
var request = g_form.getValue("requested_for");
var ga = new GlideAjax("script include name");
ga.addParam("sysparm_name", "getUserDetails");
ga.addParam("sysparm_userID", request);
ga.getXML(userDet);
}

function userDet(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var res = JSON.parse(answer);
g_form.setValue("field name", res.name); // User name

}

 

 

---------->mark if its helpful

ryo200
Tera Contributor

Entering script include seems to cause errors in function and return.

I have made the following changes, but they do not work properly.


script include

var getUserDetails = function() {
var id = this.getParameter('sysparm_userID');
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', id);
grUser.query();

var usrobj = {};
while (grUser.next()) {
usrobj.email = grUser.name.toString();
}
return JSON.stringify(usrobj);
};

use script include in this format (this is a sample for your reference) make sure it has client callable

 

--------------------------------------------------------

var CatalogClientUtil = Class.create();
CatalogClientUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserDetails: function() {
        var id = this.getParameter('sysparm_userID');
        var grUser = new GlideRecord('sys_user');
        grUser.addQuery('sys_id', id);
        grUser.query();
        var usrobj = {};
        while (grUser.next()) {
            // usrobj.email = grUser.email.toString();
            // usrobj.bphone = grUser.phone.toString();
            // usrobj.phone = grUser.mobile_phone.toString();
            usrobj.title = grUser.title.toString();


        }
        return JSON.stringify(usrobj);

    },

    type: 'CatalogClientUtil'
});
------------------------------------------------------------------------
 
Naneen_0-1697205703047.png