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

sureshp89882164
Tera Contributor

When you click on UI Action button: "Assign Remediation" need to get field values "Sub PTASK type" ,"Cause code" and "Sub Cause code" dynamically to the redirect URL "action.setRedirectURL('problem_task.do?sys_id=-1&sysparm_query=problem_task_type=remediation');"

 

UI Action:

createRemediationTask();

function createRemediationTask() {

    var query = 'problem_task_type=remediation';
    query += '^u_type_of_task=' + encodeURIComponent(current.u_type_of_task);
query += '^u_close_code=' + encodeURIComponent(current.u_close_code);
 query += '^u_root_cause=' + encodeURIComponent(current.u_root_cause);
   

    action.setRedirectURL('problem_task.do?sys_id=-1&sysparm_query=' + query);
}
 
In the new window I am able to get the value of "u_type_of_task" but not able to get dynamic values from "u_close_code" and "u_root_cause"(it displays empty fields)
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@sureshp89882164 

did you print what came in query before redirecting?

also are those fields present on form view when you are redirecting to new record?

if yes then it should work fine.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ChallaR
Mega Guru

Hi @sureshp89882164 ,

 

please find the below suggestion for fix the issue -

Suggested Fixes

  1. Ensure Fields Are Populated

    • Check if u_close_code and u_root_cause are actually set on the record before the UI Action is triggered.
  2. Make Fields Available to the Script

    • If these fields are not on the form, they might not be available in the current object in client-side scripting.
    • You can:
      • Add them to the form layout.
      • Or use a server-side GlideRecord call to fetch their values.
var gr = new GlideRecord('problem_task');
if (gr.get(current.sys_id)) {
    var query = 'problem_task_type=remediation';
    query += '^u_type_of_task=' + encodeURIComponent(gr.u_type_of_task);
    query += '^u_close_code=' + encodeURIComponent(gr.u_close_code);
    query += '^u_root_cause=' + encodeURIComponent(gr.u_root_cause);
    action.setRedirectURL('problem_task.do?sys_id=-1&sysparm_query=' + query);
}

Debug with Logging

  • Add gs.info() or console.log() statements to verify what values are being picked up.

please mark it as correct and close the thread if this is helpful.

 

Thanks,

Rithika.ch

M Iftikhar
Tera Sage

HI @sureshp89882164 ,

 

Can you please explain where you want to display the UI action and where should it redirect? to a new problem_task form? What are the types of your fields "u_close_code" and "u_root_cause"?

 

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Currently ui action button: Assign Remediation is available in Investigation task. When you click on button, it need to redirect to Remediation task. Both fields are Choice list "u_close_code" and "u_root_cause"