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

Brother!

 

You just want to get redirected to cmdb_ci_outage table right?

Because initially you said that it should create records as per your Post. 

 

Thank,

Ashutosh Munot

Sorry Bro if that was miss communicated and apologize for wasting your time.

My intention was to create a record but before that it should display the record form. 

HI,

Assuming that you dont want to submit a record but you want to redirect to it and then fill information and then submit Outage record and then redirect back to incident.


Check below script:

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var state = g_form.getValue('state');
var pri = g_form.getValue('priority');
if(pri == 1)//6 is resolved
{
var ans = confirm('Do you want to create Outage');
if(ans == true)
{
//var URL = "cmdb_ci_outage.do?sys_id=-1&sysparm_query=task_number="+g_form.getUniqueValue();
var URL="https://dev21892.service-now.com/cmdb_ci_outage.do?sys_id=-1&sysparm_query=task_number="+g_form.getUniqueValue();
alert('URL' +URL);
top.window.location = URL;
//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");


// }
}

Note: If we redirect to Outage record then incident will not be saved and it will ask you to leave page or stay. If you select leave then you will be redirected to Outage table with a new record and Task number auto populated.

Now here it will redirect you to outage record and there you will have to write on more client script on-submit which will again take you back to incident.

 

Better we use client script and script include to create record.

 

Thank you  Ashutosh for your solution and suggestions. I will check it and get back.

Great!

 

Mark answer as correct and Helpful. If you are satisfied.


Thanks,
Ashutosh Munot