I have a requirement to create incident record from HR case, I was trying the below logic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have create new UI action with below logic in UI action with client box checked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
in your UI Action, your server-side logic (the setRedirect() function with GlideRecord) is not wrapped inside the if (g_form.submitted()) or if (action == 'hr_create_incident').
That’s why it’s never triggered.
// This runs client-side when the UI Action button is clicked
function hr_create_incident() {
if (g_form.getValue('cmdb_ci') == "") {
g_form.setDisplay('cmdb_ci', true);
g_form.setMandatory('cmdb_ci', true);
g_form.showFieldMsg('cmdb_ci', 'Please select the appropriate CI', 'error');
return false;
}
g_form.showFieldMsg('cmdb_ci', 'Appropriate CI is selected', 'info');
// Submit to server-side part of this UI Action
gsftSubmit(null, g_form.getFormElement(), 'hr_create_incident');
}
// This runs ONLY on the server side
if (typeof window == 'undefined') {
if (action == 'hr_create_incident') {
gs.info('executing server side script');
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = current.short_description;
inc.caller_id = current.subject_person;
inc.insert();
}
}
try this .. and if it doesn't work you can make separate script include and call it in ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@garimakharb - This still doesn't seems to be working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8m ago
@garimakharb I have created UI action in "Human Resource Core" scope and incident table will be usually in global scope. Does that make some difference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
22m ago
Hi @shaikimran4 ,
The reason your server side code inside the UI Action isn’t executing is likely because with Client = true, all the code inside the script is treated as client side by default and current, gs, GlideRecord, action.setRedirectURL() etc. aren’t available there, so to make it work you need to split your logic:.......validate client side first, then use gsftSubmit() to call the same UI Action name and in the server side block (wrapped by if (typeof window == 'undefined')) do the GlideRecord insert/update and redirection....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/