The CreatorCon Call for Content is officially open! Get started here.

To add Dynamic field values to the redirect url of the UI Action button

sureshp89882164
Tera Contributor

Hi All,

can you please help the below UI Action script  in the new window also fill in:

  • Sub PTASK type = same as the Investigation PTASK
  • Cause code and Sub cause code = same as the Investigation PTASK

UI Action:

createRemediationTask();

function createRemediationTask() {

    var rec = new GlideRecord('problem_task');

    rec.initialize();
    rec.problem = current.problem;
    rec.problem_task_type = 'remediation';
    rec.short_description = 'Remediation';
    if (current.u_type_of_task == 'Preliminary') {
        rec.u_type_of_task = 'Others';
    } else {
        rec.u_type_of_task = current.u_type_of_task;
    }

    rec.priority = current.priority;
    rec.cmdb_ci = current.cmdb_ci;
    rec.due_date = current.due_date;
    rec.assignment_group = current.assignment_group;
    rec.assigned_to = current.assigned_to;
    // other fields you want to map
    if (current.u_close_code != '') {
        rec.u_close_code = current.u_close_code;
    }
    if (current.u_close_code != '') {
        rec.u_root_cause = current.u_root_cause;
    }

    rec.insert();
   
    action.setRedirectURL(rec);
}
1 REPLY 1

Bhimashankar H
Mega Sage

Hi @sureshp89882164 ,

 

Add below code snippet after record insert

    // Insert the record first
    var newRecordSysId = rec.insert();

    // Open in new window instead of redirecting current window
    var newRecordUrl = rec.getLink(true);
    
    // Use client-side script to open in new window
    var script = "window.open('" + newRecordUrl + "', '_blank');";
    
    // Alternative approach - set redirect but with target blank
    action.setRedirectURL(newRecordUrl + '&sysparm_target=_blank');

 

Refer the below post:

UI action to open in new window/Tab 

Create link of record in UI action and Redirect 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!