How to use Modal value in server-side through UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2023 12:48 AM
I am using a UI Action button which on click opens a modal. In the modal I am able to select a value and the field is of "Reference" type. I have written the below script in the UI Action but the issue that I am facing is for a field named 'u_control_id' which is of "List Collector" type. The field is not being updated properly where as the description field is getting updated. For few milliseconds while loading, the list collector field shows the added record and then it is redirected to another form. When I refresh the old form then the value is not present in that list collector field.
My requirement is to populate the value from the modal and update the current object and the redirect the user to another form. I am also unable to get the modal value to the server side script. How can I get the modal value to the server-side script?
The code is pasted below.
function createCTRLTask() {
try {
var gm = new GlideModal('create_control_task', true);
gm.setTitle('Create a Control Task');
gm.setWidth(400);
gm.setPreference("onPromptComplete", function(value) {
var control_string = g_form.getValue('u_control_id');
if (control_string != "") {
var control_array = control_string.split(',');
control_array.push(value);
g_form.setValue('u_control_id', control_array);
} else {
var emp_array = [];
emp_array.push(value);
alert(JSON.stringify(emp_array));
g_form.setValue('description', 'Updated from UI Action');
g_form.setValue('u_control_id', emp_array);
}
gsftSubmit(null, g_form.getFormElement(), 'ctrl_task');
});
gm.setPreference("onPromptCancel", function(value) {
return false;
});
gm.render();
} catch (e) {
alert(e.message);
}
}
if (typeof window == 'undefined') {
controlTask();
}
function controlTask() {
try {
var suffix = current.sys_id;
var prefix = "https://dev12345.service-now.com/u_control_task.do?sys_id=-1&sysparm_query=parent=";
var url = prefix + suffix;
current.update();
action.setRedirectURL(url);
} catch (e) {
gs.log(e.message, "UI RM");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2023 01:31 AM
what are you trying to achieve?
I could see you are getting value from u_control_id, doing split and again setting the same value.
Please share some screenshots and share what's your business requirement
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2023 02:07 AM
Hello,
I think you don't need server side part whcih is just redirecting that could interupts the client action of submit.
Try the redirect on client side after the gsftSubmit line using window.open(URL);