Script not working in UI action

Akshat2404
Tera Contributor

I am facing an issue while running the script in UI action. The client side script is executed but the server side script is not getting executed even if i use gsftSubmit().

Here is the code: 

function alertUser() {
if (confirm("Are you sure you want to create a child incident of current incident?")) {
alert("your record is created");
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
}

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



function createChildIncident() {
var g = new GlideRecord('incident');
g.initialize();
g.caller_id = current.caller_id;
grec.parent_incident = current.sys_id;
g.short_description = current.short_description;
g.insert();
action.setRedirectURL(current);
}
7 REPLIES 7

@Akshat2404 

Please make sure client checkbox button is true on the UI action also in OnClick field you should call alertUser()

. Further please apply some log in createChildIncident() function to check where code is getting failed.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Abhijeet_Pawar
Tera Guru

Hello @Akshat24042404, please try below tried and tested code.

function alertUser() {
if (confirm("Are you sure you want to create a child incident of current incident?")) {
alert("your record is created");
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
}

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

function createChildIncident() {
var g = new GlideRecord('incident');
g.initialize();
g.caller_id = current.caller_id;
g.parent_incident = current.sys_id;
g.short_description = current.short_description;
g.insert();
action.setRedirectURL(current);
}

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 

Thanks and Regards,
Abhijeet Pawar.

 

shashi123
Tera Contributor

Hello @Abhijeet_Pawar I am working on the same requirement above mentioned code is working fine for me.

 

Thank You,