UI Action core ui + workspace issue

flsn2
Tera Expert

I need help with ui action

 

I'm trying to use a client script with a server side script.

 

But it needs to work with core ui and workspace.

 

from what i made i only works on workspace and not core ui

 

// --- Client Script CORE UI AND WORKSPACE Side ---
function closeassetTaskCombined() {
    // Perform client-side actions needed in both environments
    g_form.setValue('state', 3); // Set state visually first


    // Check if g_form.submit exists (reliable indicator for Workspace/modern UI)
    if (typeof g_form.submit === 'function') {
        // Environment is likely Workspace or similar modern UI
        // Use g_form.submit to trigger the server script via Action Name
        g_form.submit('close_asset_task'); // MUST match 'Action name' field
    } else {
        // Environment is likely Core UI (Platform)
        // Use gsftSubmit to trigger the server script via Action Name
        gsftSubmit(null, g_form.getFormElement(), 'close_asset_task'); // MUST match 'Action name' field
    }
}


// --- Server Side ---
current.state = 3; // Ensure '3' is the correct value for 'Closed Complete'
current.work_notes = 'Task completed via UI Action';
current.update();


gs.addInfoMessage('Asset Task has been completed.');
action.setRedirectURL(current);
1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @flsn2 
Need few modifications to your script.
Try below script and let me know if you have any queries.


Name: Update Short description 

Action name: update_sd

OnClick:  runClientSideScript();

Core UI client script:

function runClientSideScript() {
    g_form.setValue("short_description", "Updated from the new custom ui action.");
    gsftSubmit(null, g_form.getFormElement(), "update_sd");
}
if (typeof window == 'undefined') {
    runServerSideScript();
}

function runServerSideScript() {
    current.update();
    action.setRedirectURL(current);
}

Workspace script:

function onClick(g_form) {
    g_form.setValue("short_description", "Updated from the new custom ui action.");
    var actionName = g_form.getActionName();
    g_form.submit(actionName);

}

 

JSiva_0-1744085789636.pngJSiva_1-1744085817766.png


Hope this helps.
Regards,
Siva

View solution in original post

4 REPLIES 4

J Siva
Tera Sage

Hi @flsn2 
Need few modifications to your script.
Try below script and let me know if you have any queries.


Name: Update Short description 

Action name: update_sd

OnClick:  runClientSideScript();

Core UI client script:

function runClientSideScript() {
    g_form.setValue("short_description", "Updated from the new custom ui action.");
    gsftSubmit(null, g_form.getFormElement(), "update_sd");
}
if (typeof window == 'undefined') {
    runServerSideScript();
}

function runServerSideScript() {
    current.update();
    action.setRedirectURL(current);
}

Workspace script:

function onClick(g_form) {
    g_form.setValue("short_description", "Updated from the new custom ui action.");
    var actionName = g_form.getActionName();
    g_form.submit(actionName);

}

 

JSiva_0-1744085789636.pngJSiva_1-1744085817766.png


Hope this helps.
Regards,
Siva

Hi @J Siva 

I've landed here because I'm facing the same issue.
Your input makes me see some progress like the button now is trying to do something, I see the screen blinking, but it didn't do anything other than blinking the screen.

function moveToUAT(){
	// Ensure `Skip UAT Deploy` is not flagged True if State is New
	if(g_form.getValue('state') == -5 && g_form.getValue('u_skip_uat_deploy') == 'true'){
		alert("UAT Deployment cannot be requested while `Skip UAT Deploy` is checked/true; please first Save this record or set `Skip UAT Deploy` to unchecked/false before continuing.");
		return false;
	}
	var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
	ga.addParam("sysparm_name", "getNextStateValues");
	ga.addParam("sysparm_change_sys_id", g_form.getUniqueValue());
	ga.getXMLAnswer(function(stateValues) {
		var returnedStates = stateValues.evalJSON();
		g_form.setValue("state", returnedStates[0]);
		gsftSubmit(null, g_form.getFormElement(), 'state_model_move_to_uat');
	});
}

if (typeof window == 'undefined'){
	updateAndRedirect();
}

function updateAndRedirect(){
	current.update();
	action.setRedirectURL(current);
}

 

function onClick(g_form) {
    
     var actionName = g_form.getActionName();
     g_form.submit(actionName);

}



Screenshot 2025-04-17 at 12.24.38.png


Hi @Luiz Lucena 
Everything looks good.
May i know, what value you are getting from the script include?
Have you checked that? If not, then use console.log to see the result of "returnedStates[0]".

Regards,
Siva

Not getting any value for returnedStates, we decided for now that Change Management won't be used in Service Operations Workspace due the amount of customization done. 

We will evaluate going back to OOTB with CHG. 

Thanks for your time though!