how can we assign the value of one variable as a default value to another variable

Yash38
Kilo Guru

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.

1 ACCEPTED SOLUTION

Yash38
Kilo Guru

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.

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

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();
		}
	},

 

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

Community Alums
Not applicable

Hi @Yash38 ,

 In that case try with OnSubmit client script.

 

Hi @Community Alums ,

 

Isn't there any way we can do this by writing a single line code under default value of the variable?