Client Callable Script Include

SumanthMora
Mega Guru

Hi Folks,

I have created a client callable script include .

When answer is true it it should make a call to Script Include to create a new record

Please find the code below where it is not working as expected. kindly suggest if anything wrong.

Script Include:

var createoutage = Class.create();
createoutage.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	incidentoutage: function(){
		var incout = new GlideRecord('cmdb_ci_outage');
		incout.initialize();
		incout.setValue('task_number',this.getParameter('sysparm_sys_id'));
		incout.setValue('cmdb_ci',this.getParameter('cmdb_ci'));
		var incoutid = incout.insert();
		
		var tskout = new GlideRecord ('task_outage');
		tskout.setValue('task',this.getParameter('sysparm_sys_id'));
		tskout.setValue('outage',incoutid);
		tskout.insert();
		
		action.setRedirectURL(incout);
		action.setReturnURL(current);
		
	},
	
	type: 'createoutage'
});

 

Client Script:

 

function onSubmit() {
	
	var pri = g_form.getValue('priority');
	var status = g_form.getValue('state');
	
	if (pri == 1 && status == 6){
		var ans = confirm('Do you want record to be created');
		if(ans){
			var ajax  = new GlideAjax ('createoutage');
			ajax.addParam('sysparm_name','incidentoutage');
			ajax.getXML(createout);
			
			function createout(response){
				var answer = response.responseXML.documentElement.getAttribute("answer");
				
				
			}
			
		}
		
	}
}

 

Thanks

Sumanth

1 ACCEPTED SOLUTION

Hi,

 

Here you go this is you final code:

 

Client Scripts:

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var state = g_form.getValue('state');
var pri = g_form.getValue('priority');
if(state == 6 && pri == 1)//6 is resolved
{
var ans = confirm('Do you want to create Outage');
if(ans == true)
{
alert('Here');
var ajax = new GlideAjax ('createoutage');
ajax.addParam('sysparm_name','incidentoutage');
ajax.addParam('sysparm_sys_id',g_form.getUniqueValue());
ajax.addParam('cmdb_ci',g_form.getValue('cmdb_ci'));
ajax.getXML(createout);
}

}
function createout(response){
var answer = response.responseXML.documentElement.getAttribute("answer");


}
}

 

Script Include:

var createoutage = Class.create();
createoutage.prototype = Object.extendsObject(AbstractAjaxProcessor, {

incidentoutage: function(){
var incout = new GlideRecord('cmdb_ci_outage');
incout.initialize();
incout.task_number = this.getParameter('sysparm_sys_id');
incout.cmdb_ci = this.getParameter('cmdb_ci');
var incoutid = incout.insert();

var tskout = new GlideRecord ('task_outage');
tskout.initialize();
tskout.setValue('task',this.getParameter('sysparm_sys_id'));
tskout.setValue('outage',incoutid);
tskout.insert();

action.setRedirectURL(incout);
action.setReturnURL(current);

},

type: 'createoutage'
});

 

See below screen shot for Outages created:

find_real_file.png

 

Thanks,
Ashutosh Munot

 

Mark it correct or helpful

View solution in original post

14 REPLIES 14

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

First of all tell me from where this is coming: this.getParameter('sysparm_sys_id');

and this.getParameter('cmdb_ci'); i dont see this parameter you are passing from client script.

Also You have not initialized : See below code:

 

 

var tskout = new GlideRecord ('task_outage');

tskout.initialize();

tskout.setValue('task',this.getParameter('sysparm_sys_id'));

tskout.setValue('outage',incoutid);

tskout.insert();

 

Thanks,,
Ashutosh Munot

Hi Ashutosh,

Thanks for the response. Actually my requirement is to create a new outage record when the user try to resolve P1 incidents.

So, a pop up should display asking for confirmation. If yes it should open the new outage record form for the current incident.

Kindly suggest/let me know the above script is correct for this requirement.

Thanks

Sumanth

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

How user are resolving this incidents.

 

If you are using a UI action then what i will do is:

1) Use Confirm Box in UI action.

2) Check Response if yes or no.

3) If no then what should happen?

4) If yes then Outage record should be created.

5) If UI action is used then we dont have to use script include. We can use Client side as well as Server side code here.


Thanks,
Ashutosh Munot

User will resolve the incident manually. While doing it before submit a popup should display yes or no. If yes outage record should create, else allow submission.

> There a OOO Ui action "Create Outage".

Can you please provide any sample code.

Thanks

Sumanth