Standard Change Proposal Client Script error only for non-admin or non-management users?

MBarrott
Mega Sage

Running into a weird error with a client script which is only impacting users that are not admin or a manager.

 

Admins and managers are able to submit a Standard Change Proposal just fine. Anyone else gets a "Submit canceled due to a script error - please contact your System Administrator" error pop up. 

 

This Client Script follows two logic paths:
1. When user is attempting to update record, script will review the state of the record to see if user is attempting to close record. If so, it will check to see if any time has been documented in time_worked - aborting action and prompting for input
2. When user is attempting to update record, script will review the returned scratchpad value from server to see if any time has been documented today and whether or not the time_worked field currently matches what was documented on initial load - aborting action and prompting for input if no time has been entered today or with this particular data entry

Note: Logic path #2 likely covers for the check in #1 but original logic is being retained to simply keep unnecessary conflict with extended tables and ensure correct syntax with error alerts. Will review and update to singular logic check once confirmed no issues.

 

Script is as follows:

function onSubmit() 
{
	// retrieve name of table and declare varaiable(s)
	var table = g_form.getTableName();
	var returnVal;
	
	switch(table)
	{
		case 'problem': // problem table	 
			returnVal = problemTable(returnVal);
			break;
			
		case 'problem_task': // problem task table
			returnVal = problemTaskTable(returnVal);
			break;
			
		case 'dmn_decision': // demand decision table
			returnVal = dmnDecisionTable(returnVal);
			break;	

		case 'pm_project_task': // project task table
			returnVal = projectTaskTable(returnVal);
			break;	
			
		default: // task and all inherited tables with matching state field values/formats
			returnVal = defaultTable(returnVal);
			break;	
	}
	
	// if - check to see if user is attempting to close record with no documented time 
	// else if - check to see if any time has been reported today and prompt user if not found
	if(returnVal == 0) 
	{
		alert('Please enter total time worked on this record.');
		return false;
	} 
	else if(g_scratchpad.timeUpdates == '0' && g_form.getValue('time_worked').toString() === g_scratchpad.savedTime)
	{
		alert('Please enter total time for this record update.');
		return false;
	}
}

function problemTable(returnVal) // problem function
{
		var choiceValue = g_form.getValue('state'); // get value for state field

		// check time worked value and see if a closing state has been selected
		if(g_form.getValue('time_worked') == '00:00:00' && (choiceValue == '107'))
		{
			returnVal = 0;
			return returnVal;
		}	
	return returnVal;	
}

function problemTaskTable(returnVal) // problem task function
{
		var choiceValue = g_form.getValue('state'); // get value for state field

		// check time worked value and see if a closing state has been selected
		if(g_form.getValue('time_worked') == '00:00:00' && (choiceValue == '157'))
		{
			returnVal = 0;
			return returnVal;
		}	
	return returnVal;	
}
	
function dmnDecisionTable(returnVal)  // demand decision function
{
	// get value for state field, the retrieve label for that respective state
	var choiceValue = g_form.getValue('decision_state');
	var choiceLabel = g_form.getOption('decision_state', choiceValue).text;

	// check time worked value and see if a closing state label has been selected
	if(g_form.getValue('dmn_decision.time_worked') == '00:00:00' && (choiceLabel == 'Closed Complete' || 
																	 choiceLabel == 'Closed Incomplete' || 
																	 choiceLabel == 'Closed Skipped'))
	{
		returnVal = 0;
		return returnVal;
	}
}

function projectTaskTable(returnVal) // project task function 
{
	// parent project tasks have the state field change to read-only which negatively impacts the script
	// parent project tasks have their time_worked field increment automatically so no longer require enforcement


	var prjTaskAjax = new GlideAjax('ProjTaskParentCheck'); // declare script include to call
	prjTaskAjax.addParam('sysparm_name','parentCheck'); // declare function call within script include
	prjTaskAjax.addParam('sysparm_sys_id', g_form.getUniqueValue()); // pass over sys_id of current record
	prjTaskAjax.getXML(parentCheck);

	function parentCheck(response)
	{
		// receieve response returned by GlideAjax query
		var parentValue = response.responseXML.documentElement.getAttribute('answer');

		if(parentValue == 0) // value 0 means no child records were found from script include query
		{
			// get value for state field, the retrieve label for that respective state
			var choiceValue = g_form.getValue('state');
			var choiceLabel = g_form.getOption('state', choiceValue).text;

			// check time worked value and see if a closing state label has been selected
			if(g_form.getValue('time_worked') == '00:00:00' && (choiceLabel == 'Resolved' || 
																choiceLabel == 'Deferred' || 
																choiceLabel == 'Closed Complete' || 
																choiceLabel == 'Closed Incomplete' || 
																choiceLabel == 'Closed Skipped' || 
																choiceLabel == 'Closed No Customer Response' || 
																choiceLabel == 'Duplicate Ticket' || 
																choiceLabel == 'Incorrect Ticket Type'))
			{
				returnVal = 0;
				return returnVal;
			}
		}
	}
}
	
function defaultTable(returnVal) // default function 
{
	// get value for state field, the retrieve label for that respective state
	var choiceValue = g_form.getValue('state');
	var choiceLabel = g_form.getOption('state', choiceValue).text;

	// check time worked value and see if a closing state label has been selected
	if(g_form.getValue('time_worked') == '00:00:00' && (choiceLabel == 'Resolved' || 
														choiceLabel == 'Deferred' || 
														choiceLabel == 'Closed Complete' || 
														choiceLabel == 'Closed Incomplete' || 
														choiceLabel == 'Closed Skipped' || 
														choiceLabel == 'Closed No Customer Response' || 
														choiceLabel == 'Duplicate Ticket' || 
														choiceLabel == 'Incorrect Ticket Type'))
	{
		returnVal = 0;
		return returnVal;
	}
}

 

 

 

 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Access to the Script Include is a probable culprit.  You could confirm this by breaking down the client script or test case to not execute the GlideAjax, and add alerts to confirm the other users see the scratchpad variable, etc.  Is the Script Include in the Global scope?  If not is it accessible from all application scopes?  Do you have any Access Controls with a certain user role listed in the related list? 

Hey @Brad Bowman  - I think I found the root cause. 

Did some testing and it looks like it is falling into the defaultTable function (as expected) but the script fails when reading the state field since it is read-only for certain users. Confirmed this isn't read only for the users which the submissions work for so I will be investigating where/what the condition or policy is for this read-only state.