How to call a script include in a UI action

Mi1
Tera Contributor

Hi,

I want to set the value I get in the script include in the UI action.

A target_group is a type that refers to a cmn_department.

I just want to return the value I got in the script include here.

How can I write?

 

Following code doesn’t work : UI Actions 

current.target_user = gs.getUserID();

function confirmCreate() {
var ga = new GlideAjax('scriptincludename');
ga.addParam('sysparm_name', 'getUserDepartmentList');
ga.addParam('sysparm_id', g_form.getValue('target_user'));
ga.getXML(updateCampus);
}

function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
gsftSubmit(null, g_form.getForElement(), 'copy_release');
}
if (typeof window == 'undefined')
current.target_group = doCreate();

function doCreate() {
new scriptincludename().getUserDepartmentList();
}
current.update();

 

Regards,

1 ACCEPTED SOLUTION

Arpit Modi
Tera Expert

You do not need to include client side code in UI action, only server side code is enough. Please use similar code in the UI action.

 

current.target_group = new scriptincludename().getUserDepartmentList(gs.getUserID());

current.update();

 

In the script include function, use the user id to perform appropriate search and return value which you want to set in target_group

View solution in original post

3 REPLIES 3

Arpit Modi
Tera Expert

You do not need to include client side code in UI action, only server side code is enough. Please use similar code in the UI action.

 

current.target_group = new scriptincludename().getUserDepartmentList(gs.getUserID());

current.update();

 

In the script include function, use the user id to perform appropriate search and return value which you want to set in target_group

Mi1
Tera Contributor

 

Hi,

Thank you.

I worked it.

Best Regards,

snowycode
Tera Contributor

Hi @Mi1 - as Arpit mentioned, only the server side code is needed in the UI Action script.

 

You can pass in the User ID (using gs.getUserID) to the script include as a parameter, perform the logic in the script include, and then return it back to the UI Action and set the target_group.

 

 

Please mark Correct or Helpful if my response helped you.

You can also find a full guide for how to call a script include from UI Action here.