GlideAjax returning null

jiral
Giga Sage

I have a UI Action that calls a UI page  that do a GlideAjax to update the task activity due but it does not work

 

UI Page HTML

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<j:set var="jvar_sysid" value="${RP.getWindowProperties().get('sysid')}"/> 
	<j:set var="jvar_tablename" value="${RP.getWindowProperties().get('table_name')}"/>  

	<style type="text/css">
		.tg  {border-collapse:collapse;border-spacing:0;margin:0px auto;}
		.tg td{border:none;font-size:14px;
		overflow:hidden;padding:10px 5px;word-break:normal;}
		.tg th{border:none;font-size:14px;
		font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
		.tg .tg-uns3{text-align:center;vertical-align:middle}
		.tg .tg-q7tc{text-align:center;vertical-align:middle}
		@media screen and (max-width: 767px) {.tg {width: auto !important;}.tg col {width: auto !important;}.tg-wrap {overflow-x: auto;-webkit-overflow-scrolling: touch;margin: auto 0px;}}
	</style>

	<div class="tg-wrap"><table class="tg">
		<tbody>
			<tr>
				<td class="tg-q7tc" colspan="2"><g:ui_date name="datetime" id="datetime"/></td>
			</tr>
			<tr>
				<td class="tg-q7tc" colspan="2"><g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/></td>
				<input type="hidden" id="task_table" name="task_table" value="${jvar_tablename}"/>		
				<input type="hidden" id="task_sysid" name="task_sysid" value="${jvar_sysid}"/>
			</tr>
		</tbody>
		</table>
	</div>	

</j:jelly>

 

UI Page Client Script

 

function onCancel() {
	GlideDialogWindow.get().destroy();
	return false;
} 

function onSubmit() {
	var dateval = document.getElementById('datetime').value;
	var fxtime = '18:00:00';
	var tbl = document.getElementById('task_table').value;
	var id = document.getElementById('task_sysid').value;

	if(dateval =='')
	{
		alert("${JS:gs.getMessage('Date selection is required.')}");
		return false;
	}
	
	alert("REC:" + id + "\nTBL : "+ tbl+ "\nDATE SELECTED : "+ dateval+ "\nFIXED TIME : "+ fxtime);
	var ga = new GlideAjax('ReleaseNotify');
	ga.addParam('sysparm_name','setRelease');
	ga.addParam('sysparm_sys_id',id);	
	ga.addParam('sysparm_tbl',tbl);
	ga.addParam('sysparm_date',dateval);
	ga.addParam('sysparm_time',fxtime);
	ga.getXML(function getAnswer(response) {
		var result = response.responseXML.documentElement.getAttribute("answer");
		alert(result);
		if(result == false)
		{
			GlideDialogWindow.get().destroy();
			g_form.addErrorMessage("No deployment task exist. Make sure that all prior tasks are completed.");
			return false;
		}else{
			GlideDialogWindow.get().destroy();
			alert(result);
		}
	});

	//window.open('/'+tbl+'.do?sys_id='+id,'_self');
	//g_form.addInfoMessage('Items scheduled for release on ' + dateval);

}

 

Script Include:

 

	setRelease:function(){
		var rec = this.getParameter('sysparm_sys_id');
		var tbl = this.getParameter('sysparm_tbl');
		var dateval = this.getParameter('sysparm_date');
		var time = this.getParameter('sysparm_time');

		if(tbl == 'sc_req_item')
		{
			var sctask = new GlideRecord('sc_task');
			sctask.addQuery('active', true);
			sctask.addQuery('request_item', rec);
			sctask.addQuery('short_description', 'Deployment');
			sctask.query();
			if(sctask.next())
			{
				return 'Hello';
			}else{
				return 'Good Morning';
			}
		}

	},

 

Any idea why it's returning null instead of the expected 'Hello'/'Good Morning'?

1 ACCEPTED SOLUTION

jiral
Giga Sage

Found it. Seems like this part was the culprit:

initialize: function() {
},

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@jiral 

Is your script include client callable?

Did you check script include is getting called or not?

try adding logs in script include & check

setRelease:function(){
var rec = this.getParameter('sysparm_sys_id');
var tbl = this.getParameter('sysparm_tbl');
var dateval = this.getParameter('sysparm_date');
var time = this.getParameter('sysparm_time');

gs.info("rec" + rec);

if(tbl == 'sc_req_item')
{
var sctask = new GlideRecord('sc_task');
sctask.addQuery('active', true);
sctask.addQuery('request_item', rec);
sctask.addQuery('short_description', 'Deployment');
sctask.query();
if(sctask.next())
{
return 'Hello';
}else{
return 'Good Morning';
}
}

},

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

jiral
Giga Sage

It is.

jeffiral_0-1697549076201.png

 

I added gs.info("rec" + rec); but I'm not getting result. No info shows show up but got this alert

jeffiral_1-1697549145588.png

Got this one when validating the data to pass to the Ajax and this confirmed that the data are valid.

jeffiral_2-1697549970771.png

 

And here's the UI action where the UI page is called from

 

function showPage(){
	var gdw = new GlideModal('release_date',true);
	gdw.setTitle('Select target release date');
	gdw.setWidth(10);
	gdw.setPreference('table_name', g_form.getTableName());
	gdw.setPreference('sysid', g_form.getUniqueValue());
	gdw.render();
}

 

jiral
Giga Sage

Found it. Seems like this part was the culprit:

initialize: function() {
},