Getting Variable Value from RITM using Item Option table

Steven Parker
Giga Sage

Looking for some help.  I am just testing something and have a script to try and grab the variable values from an RITM.

 

 

//Just testing - RITM Sys ID
var ritmSysID = '413300509730ed10145b3b6e6253af31';

var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('sc_item_option.item_option_new','e118bfd5db22bb00c53974dfaa96197a'); //Gap Owner Review Details Variable
gr.addQuery('request_item',ritmSysID);
gr.query();
if (gr.next()) {
		alert("GAP OWNER REVIEW DETAILS: " + gr.sc_item_option.value);
}

 

 

 

I keep getting 'undefined' no matter what I try to do (and I've tried a lot).  Now, if I add 'gr.request_item' in the Alert it returns the correct RITM SYS_ID so I know I am connected to the correct record.  I just want to get the 'gap_owner_review_detail' variable value.

 

Any help?


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
8 REPLIES 8

You can't dot-walk GR results in a Client Script - you only have visibility into the fields returned by the GR, not fields related to the returned fields - which is another reason why it's not supported.

So I changed to a GlideAjax/Script Include and everything is working but one thing now...the task still saves/closes even if it hits the IF Statement and return false;.  I am not sure GlideXMLWait() is supported any longer.  What can I modify on this to make this wait for the results to return?  Essentially make that return false; work correctly and not allow the form to save/close.

 

Client script:

 

function onSubmit() {
	//Just getting the old value and new values from the form when they are trying to submit
	var el_id = g_sc_form.getControl('gap_owner_review_detail').id;
	var orig_val = gel("sys_original."+ el_id).value;
	var new_val = g_form.getValue("gap_owner_review_detail");
	if(orig_val != new_val){
		alert("NEW VAL: " + new_val + " | ORIG VAL: " + orig_val);
	}

	var ritmSysID = g_form.getValue('request_item');
	
	//Getting Gap Review Detail Variable
	var ga = new GlideAjax('checkRecords');
	ga.addParam('sysparm_name', "checkRecordPresent");
	ga.addParam('sysparm_ritm', ritmSysID); // give here user_id variable name
	ga.getXMLAnswer(function(answer){
	if(answer != ''){
			alert("OLD GAP OWNER VALUE: " + orig_val + " | GAP OWNER VARIABLE DATA: " + answer);
			if(orig_val != answer){
				alert("THEY DO NOT MATCH - SOMEONE ELSE UPDATED THEIR TASK");
				g_form.submitted = false; 
				return false;
			}
		}
	});
	//Type appropriate comment here, and begin script below

}

 

 

Script Include:

 

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

	checkRecordPresent: function(){

		var id = this.getParameter('sysparm_ritm');			

		var gr = new GlideRecord('sc_req_item');
		gr.addQuery('sys_id', id);
		gr.query();
		if(gr.next()){
			return gr.variables.gap_owner_review_detail;  // use valid variable name here
		}
	},

	type: 'checkRecords'
});

 


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Can you try below and see if that helps?

 


function onSubmit() {
	//Just getting the old value and new values from the form when they are trying to submit
	var el_id = g_sc_form.getControl('gap_owner_review_detail').id;
	var orig_val = gel("sys_original."+ el_id).value;
	var new_val = g_form.getValue("gap_owner_review_detail");
	if(orig_val != new_val){
		alert("NEW VAL: " + new_val + " | ORIG VAL: " + orig_val);
	}

	var ritmSysID = g_form.getValue('request_item');
	
	//Getting Gap Review Detail Variable
	var ga = new GlideAjax('checkRecords');
	ga.addParam('sysparm_name', "checkRecordPresent");
	ga.addParam('sysparm_ritm', ritmSysID); // give here user_id variable name
ga.getXMLAnswer(setAnswer);
return false;

function setAnswer(answer){
	if(answer != ''){
			alert("OLD GAP OWNER VALUE: " + orig_val + " | GAP OWNER VARIABLE DATA: " + answer);
			if(orig_val != answer){
				alert("THEY DO NOT MATCH - SOMEONE ELSE UPDATED THEIR TASK");
				g_form.submitted = false; 
				return false;
			}
		}
	}
}

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Basheer
Mega Sage

Hi @Steven Parker ,

GlideRecord doesn't provide you the values with dot walk with 100% accuracy. You need to use Script Include and check the things over here as per my view.

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.