I want to know how to set the initial value for a new record using the URL.

bonsai
Mega Sage

My purpose is to copy an existing record and display a new record form using the UI action "Record Copy" created with a client-side script.

 

g_navigation.open(table_name + '?sys_id=-1&sysparm_view=viewname');

 

 

I want to get the display value of an existing record using "g_form.getEditableFields();" and set it in a new record.

 

I thought it would be possible to set the field value with "sysparm_query=" in the setting value of "g_navigation.open", but it doesn't work.

 

Can I copy the value of an existing field to a new record using a URL?

 

 

I think record copying can be done easily using a server-side script, but I would like to use client-side ``g_navigation.open'' to implement record copying with required fields left blank.

 

 

 

2 ACCEPTED SOLUTIONS

Maik Skoddow
Tera Patron
Tera Patron

Hi @bonsai 

you were on the right path: "sysparm_query" parameter has to be leveraged for prefilling fields with values. If you want to see this in action you can go to the list view of any table (in my example "incident") and lookup any values. In the below example I filter for a certain caller:

 

MaikSkoddow_0-1704855303592.png

 

Then click on the "New" button and examine the resulting URL. In the form view of a new record you will see that the caller field is prepopulated the previous filter:

MaikSkoddow_1-1704855402757.png

Maik

 

 

View solution in original post

Harish KM
Kilo Patron
Kilo Patron

Hi @bonsai here is the example through UI Action client callable. It creates a new record on change request table

function redirectToChg(){

var desc = g_form.getValue('description'); //RITM desc
var sd = g_form.getValue('short_description'); //RITM short desc

 

//Base URL for creating a new CHG record and to map fields via 'sysparm_query' parameter
var url = '/change_request.do?sys_id=-1&sysparm_query=';

 

//Query parameter to map fields on CHG form.
var urlParams = 'description=' + encodeURIComponent(desc) + '^short_description=' + encodeURIComponent(sd);


//Open CHG in new window
g_navigation.open(url + urlParams, '_blank');
}

 

Make sure your onclick value matches the function name

 

HarishKM_0-1704855789252.png

Regards
Harish

View solution in original post

2 REPLIES 2

Maik Skoddow
Tera Patron
Tera Patron

Hi @bonsai 

you were on the right path: "sysparm_query" parameter has to be leveraged for prefilling fields with values. If you want to see this in action you can go to the list view of any table (in my example "incident") and lookup any values. In the below example I filter for a certain caller:

 

MaikSkoddow_0-1704855303592.png

 

Then click on the "New" button and examine the resulting URL. In the form view of a new record you will see that the caller field is prepopulated the previous filter:

MaikSkoddow_1-1704855402757.png

Maik

 

 

Harish KM
Kilo Patron
Kilo Patron

Hi @bonsai here is the example through UI Action client callable. It creates a new record on change request table

function redirectToChg(){

var desc = g_form.getValue('description'); //RITM desc
var sd = g_form.getValue('short_description'); //RITM short desc

 

//Base URL for creating a new CHG record and to map fields via 'sysparm_query' parameter
var url = '/change_request.do?sys_id=-1&sysparm_query=';

 

//Query parameter to map fields on CHG form.
var urlParams = 'description=' + encodeURIComponent(desc) + '^short_description=' + encodeURIComponent(sd);


//Open CHG in new window
g_navigation.open(url + urlParams, '_blank');
}

 

Make sure your onclick value matches the function name

 

HarishKM_0-1704855789252.png

Regards
Harish