Incident, g_form.getValue('sys_id'); , not populating with sysID in my ajax script

Mitch Moses
Giga Expert

I have changed the getValue to get the number incident field and it returns the INC...32 number when I use it to my script include. So I think my setup is right. I am using this to check if the current incident has any child incidents on state change and then if the state is resolved or closed then make primary child ticket mandatory.

ajax client script onChange on State field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		
	}
	var state2 = g_form.getValue('state'); 
	if((state2 =="6" || state2 == "5" )){
		var test= g_form.getValue('sys_id'); //calls ajax script to look for child incs. SysId isn't populating when I check the logs from my script include
		var check = new GlideAjax('LookForChildIncs');
		check.addParam('sysparm_name', 'LookForChildIncs');
		check.addParam('sysparm_sys_id', test);
		check.getXMLWait(); //grabs xml from script include
		var answ = check.getAnswer(); //have to grab answer field from xml
		
		jslog(answ);
		
		if(answ === "true"){ //answ returns a string
			// want to make this field mandatory on resolve/closed and if it is a parent ticket
			if(g_form.getValue('parent') === ""){
				g_form.setMandatory('u_primary_child_ticket', true);
			}
			return;
		}
		else{
			g_form.setMandatory('u_primary_child_ticket', false);
			jslog("false for child incidents");
			return;
		}
	}
	
	else{
		g_form.setMandatory('u_primary_child_ticket', false);
		return;
	}
}

 

 

script include:

var LookForChildIncs = Class.create();
LookForChildIncs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	LookForChildIncs: function(){
		var sysID = this.getParameter('sysparm_sys_id');
		gs.log(sysID, "child");
		var rec = new GlideRecord('incident');
		rec.addActiveQuery();
		rec.addQuery("parent", sysID);
		rec.query();
		
		while(rec.next()){
			gs.log("child", "there are child incidents");
			return true;
			
		}
		gs.log("child", "there are no child incidents");
		return false;
	},
	
	
	
	type: 'LookForChildIncs'
});
1 ACCEPTED SOLUTION

Andrew Saxton -
Tera Expert

Thats because the sys_id field is not on the form. Instead use g_form.getUniqueValue().

Thanks!

View solution in original post

2 REPLIES 2

Andrew Saxton -
Tera Expert

Thats because the sys_id field is not on the form. Instead use g_form.getUniqueValue().

Thanks!

Brian Lancaster
Tera Sage

Try g_form.getUniqueValue() instead of g_form.getValue('sys_id');