UI Action Not Working In One Specific Scenario

Casey23
Tera Guru

Hello All,

 

As the subject says, we have a UI action that is not working in one specific scenario. This UI action is utilized across all TASK records in order to close a task. It hasn't been updated since 2017, which is important to note because the UI action works everywhere else and so I don't want to change it. I'm just trying to understand why it won't work in this one scenario.

 

In this scenario, a request is submitted from the catalog, approved by a manager and then the RITM and TASK from the workflow is created. Because another team is sometimes needed to be involved in this request, a manual task is being created for the other team at the RITM level. Once that team member wants to close their TASK, they are unable to. They click the "Close Task" UI action, a couple of the fields are set to read only, but the state doesn't actually change and the record isn't updated. No errors on the page or in the browser console. 

 

If I submit a different request from the catalog and go through the same process to create a manual TASK for that team, I am able to close the manual TASK successfully with the same UI action. If I compare this now successfully closed task against the one I mentioned in the above paragraph, I don't see any major differences that stick out to me as being a problem with the UI action since the conditions are minimal and appear to match between the TASKs.

 

The script being executed in the UI action is as follows:

function mihsCloseSCTask() {
    var preValue = g_form.getValue('state');
	g_form.setValue('state', 3);
	//Call the UI Action and skip the 'onclick' function
// 	gsftSubmit(null, g_form.getFormElement(), 'mihs_close_sc_task');	
	var isSuccess = gsftSubmit(null, g_form.getFormElement(), 'mihs_close_sc_task');
	if(!isSuccess)
		{
			g_form.setValue('state',preValue);
		}
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
	mihsUpdateSCTaskServer();

function mihsUpdateSCTaskServer() {

	current.state = 3;
	current.update();
}

 

Here is an image of the UI action:

2023-06-12 14_09_50-Window.png

 

Again, I confirmed the state is < 3 and that the approval is not equal to requested in both TASK types before clicking the UI action, yet the UI action is only failing for one of them. What else can I check on this to see why it isn't working?

1 ACCEPTED SOLUTION

Casey23
Tera Guru

It turns out that the issue was with an onSubmit client script, which makes a lot of sense considering that it was tied to a catalog item and that catalog item was the only one with this issue. There was a logic issue and because that task didn't meet the conditions in the onSubmit script, the script was returning false and not allowing the task to be submitted. Correcting the client script now allows for the task to be closed successfully.

View solution in original post

11 REPLIES 11

jaheerhattiwale
Mega Sage
Mega Sage

@Casey23 The different request you submitted to check was for same catalog item or different catalog item?

 

And i think there is no issue in ui action. There might be a business rule which is aborting the action in first scenario. So i would suggest to check the business rules where script contains setAbortAction and review the business rules.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

It was a different catalog item. I was trying to validate whether or not the conditions in the UI action would be met by either or both tasks, and from what I could see, the conditions were met for both TASKs.

Weird
Mega Sage

This seems to be based on the OOB UI action "Close Task" (79cc847bc611227d01a8092813683b36).
There's really nothing special there, though I feel that there's a useless g_form.setValue('state', 3) in it.

Looking at your script I don't see why it couldn't just be

function mihsCloseSCTask() {
    gsftSubmit(null, g_form.getFormElement(), 'mihs_close_sc_task');
}

if (typeof window == 'undefined')
    mihsUpdateSCTaskServer();

function mihsUpdateSCTaskServer() {
    current.state = 2;
    current.update();
}


There's really no need to set the state in client if you're doing that on server side anyway.

Anyway, the script itself should be fine. You might have other BR's that are hijacking the update and changing values before update.

Casey23
Tera Guru

As a test, I went into another instance and modified the UI action.

 

 

alert("Made it here!");
function mihsCloseSCTask() {
    var preValue = g_form.getValue('state');
	alert("PreValue variable =" + preValue);
	g_form.setValue('state', 3);
	//Call the UI Action and skip the 'onclick' function
// 	gsftSubmit(null, g_form.getFormElement(), 'mihs_close_sc_task');	
	var isSuccess = gsftSubmit(null, g_form.getFormElement(), 'mihs_close_sc_task');
	alert("IsSuccess variable =" + isSuccesss);
	if(!isSuccess)
		{
			g_form.setValue('state',preValue);
		}
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
	mihsUpdateSCTaskServer();

function mihsUpdateSCTaskServer() {
	alert("Inside of the SCTASKSERVER function");
	current.state = 3;
	current.update();
}

 

 

When I click the UI action, I get the alert for the PreValue with a value of 2 and that's it. If I click the UI action a second time, I get the same alert but with a value of 3 which confirms it's getting to the next line. 

 

Since line 9 (alert("IsSuccess variable =" + isSuccesss);) isn't being reached, I'm wondering if there is something failing on line 8 with the isSuccesss variable. But again, what doesn't make sense to me is why this works successfully everywhere else and not for a manual task on this specific catalog item. 

Remove alert from the mihsUpdateSCTaskServer() function.
It's running on server side so the alert there probably breaks the script.