The Zurich release has arrived! Interested in new features and functionalities? Click here for more

I have a requirement to create incident record from HR case, I was trying the below logic

shaikimran4
Tera Contributor

I have create new UI action with below logic in UI action with client box checked

 

if (typeof window == 'undefined')
    setRedirect();

 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');
        gsftSubmit(null, g_form.getFormElement(), 'hr_create_incident');

    }

        function setRedirect(){
        gs.info('excuting server side script');
        var inc = new GlideRecord('incident');
        inc.initialize();
        inc.short_description = current.short_description;
        inc.caller_id = current.subject_person;
        inc.insert();
 
Client side logic is executing properly but server side script is not working properly and incident record is not getting created. Can someone help me out on this issue.
2 REPLIES 2

garimakharb
Giga Guru

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

@garimakharb  - This still doesn't seems to be working