How to auto populate fields on a form from client script and open it in workspace ui ?

Snehal13
Kilo Sage

Below client script code opens new record on user table in agent workspace UI but I also want to auto populate fields like first_name, department, title on the user form that opens in agent workspace UI 

Currently, form opens but fields are not getting auto populated

 

 

var url = "now/workspace/agent/record/sys_user/-1/first_name=testing";
top.window.open(url);

 

 

How to do that ?

 

1 ACCEPTED SOLUTION

Below client script code opens new record on user table in agent workspace Ui but I also want to auto populate fields like first_name, department, title on the form that opens. 

 

 

var url = "now/workspace/agent/record/sys_user/-1/first_name=testing";
top.window.open(url);

 

 

 

View solution in original post

9 REPLIES 9

Hi @Snehal13 

 

If my understanding is correct then you want to update the user record from URL.

 

Can you try using onLoad client script on User Table

 

function onLoad() {
    g_form.addInfoMessage("loading");
    //get URL
    var gUrl = top.location.href;

   g_form.addInfoMessage(top.location.href);

    /* check if link contains "workpace" string -
    so only run this script if incident is updated by link
    OR you can use any unique word from URL*/


    if (gUrl.toString().includes('workspace')) {
        //get the Short description & department value

           var getShort = gUrl.split('&')[2].split('=')[2];
              var getDept = gUrl.split('&')[3].split('=')[1];


        /* update the form */
            g_form.setValue('short_description', getShort);
            g_form.setValue('department, getDept);
            g_form.save();
    }
}

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Not update. Open a workspace record for user table and auto populate fields like name and department 

Below client script code opens new record on user table in agent workspace Ui but I also want to auto populate fields like first_name, department, title on the form that opens. 

 

 

var url = "now/workspace/agent/record/sys_user/-1/first_name=testing";
top.window.open(url);

 

 

 

AnveshKumar M
Tera Sage
Tera Sage

Hi @Snehal13 ,

Try this.

 

https://<Instance_name>.service-now.com/sys_user.do?sys_id=-1&sys_target=sys_user&sysparm_query=first_name%3danvesh%5edepartment%3d5d7f17f03710200044e0bfc8bcbe5d43&sysparm_view=Workspace

Thanks,
Anvesh

Department not getting auto populated. Name getting auto filled. And it must open in agent workspace mode. The url you shared is for native ui