Use of g_form in a UI Script on Service Portal

Ilo Gassoway
Mega Guru

All,

My team is working to update our catalog items to function in the Service Portal. Among many hiccups we have found and worked around there is one that is quite frustrating. We have a UI script that has a lot of commonly used functions on our Service Catalog that we call frequently. In the Service Portal there are errors where g_form is undefined/unrecognized when attempting to update the form from the UI Script.  Is there a known fix for this? 

 

Thank you,

7 REPLIES 7

Ajay Cheruku
Tera Expert

Hi,

Could you please try this out.

https://community.servicenow.com/community?id=community_question&sys_id=5985c3eddbd8dbc01dcaf3231f96198d

 

Ajay,

This references widgets. I am working with a global UI script that I call from a onSubmit Client script. It is a simple script to check if certain check boxes are checked and return a true false.

onSubmitScript:

function onSubmit() {
	//Type appropriate comment here, and begin script below
	if(g_form.getValue("request_type") == "software_install"){
		var message = "";
		var softwarereq = "byod_airwatch,pcl,	haiku,	haiku,	rover,software_other";
		var mandatorycount = 1;
		var passed = CatalogItemUtilsHFHS.forceMandatoryCheckboxes(softwarereq, mandatorycount);
		if(!passed){
			//Abort the submit
			message = 'You must select at least ' + mandatorycount + ' software selection.';
			alert(message);
			return false;
		}
	}
	
}

 

CatalogItemsUtilsHFHS UI Script:

CatalogItemUtilsHFHS.forceMandatoryCheckboxes = function(mandatory, count) {
	//Split the mandatory variable names into an array
	mandatory = mandatory.split(',');
	var answer = false;
	var varFound = false;
	var numTrue = 0;
	//Check each variable in the array
	for(var x = 0; x < mandatory.length; x++){
		//Check to see if variable exists
		if(g_form.hasField(mandatory[x])){
			varFound = true;
			//Check to see if variable is set to 'true'
			if(g_form.getValue(mandatory[x]) == 'true'){
				numTrue ++;
				//Exit the loop if we have reached required number of 'true'
				if(numTrue >= count){
					answer = true;
					break;
				}
			}
		}
	}
	//If we didn't find any of the variables allow the submit
	if(varFound == false){
		answer = true;
	}
	//Return true or false
	return answer;
};

 

We get errors that g_form is not defined when attempting to submit this catalog item.

SanjivMeher
Kilo Patron
Kilo Patron

Below link could be helpful

https://community.servicenow.com/community?id=community_question&sys_id=bf201be5dbdcdbc01dcaf3231f96...Below link could be helpful

 

 


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

Sanjiv I have added the UI script to our theme and it is accessable, it is just the g_form part that is not functioning.