- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 09:47 PM
how can we assign the value of one variable as a default value to another variable
the 1st variable (Requested For) is a reference variable which refers to sys_user table and takes the default value as javascript: gs.getUserID() but the person who is submitting the request can change it some another user so that they can request on behalf of someone else.
2nd variable which i created is only visible on RITM and Task form and should take the default value as the value present in Requested For variable which end user selected while submitting the request.
what i need to write in default value of 2nd variable to achieve this.
Thank in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 04:29 AM
Found the easy way :
on submit client script can be used to copy variables with below script:
g_form.setValue('second_var_name',g_form.getValue('requested_for')); // make sure if requested for is reference then the second variable should also be reference.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 09:53 PM
Hi @Yash38 ,
Write a onChange Catalog Client Script (Sample script):-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga=new GlideAjax('script_include_name');
ga.addParam('sysparm_name','functionName');
ga.addParam('sysparm_dept',newValue);
ga.getXMLAnswer(callbackfn);
function callbackfn(answer){
if(answer)
g_form.setValue('variablename',answer);
}
}
Write Script Include as:-
//use scriptinclude as script_include_name
functionName: function(){
var x=this.getParameter('sysparm_dept');
var gr=new GlideRecord('cmn_department');
gr.get(x);
if(gr.next()){
return gr.dept_head.toString();
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 10:11 PM - edited 12-29-2022 10:11 PM
what if the person who is raising the request do not change the value in Requested for field.
i want the value of 1st variable while submitting the request to be copied in 2nd variable which is not being displayed on catalog form but only on RITM and task form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 10:21 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 01:16 AM
Hi @Community Alums ,
Isn't there any way we can do this by writing a single line code under default value of the variable?