Action name: type_button_action
Onclick : ClientSideScript()
Script:
function ClientSideScript() { g_form.setMandatory("short_description", false); gsftSubmit(null, g_form.getFormElement(), 'type_button_action'); //MUST call the 'Action name' set in this UI Action } //Ensure call to server-side function with no browser errors if (typeof window == 'undefined') runBusRuleCode(); //Server-side function function runBusRuleCode() { var gr = new GlideRecord("incident"); gr.initialize(); gr.short_description = "test"; var getsys = gr.insert(); current.short_description = "insert"; current.update(); GlideSysAttachment.copy('change_request', current.sys_id, 'incident', getsys); gs.addInfoMessage('You did it!'); action.setRedirectURL(current); }
UI action code to insert record in table with attachment ServiceNow?
Working Code Asked question August 11, 2023