how to set default value of one variable from another variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 02:04 AM
first variable : list of departments
second variable : list of users but the default value should be the head of the department selected in the first variable.
how to achieve this ?
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 02:15 AM
The concept of default value does not allow copying from one to the other. There is no ordering which default value will be computed 1st so that such a dependency could reliably be applied.
If one variable can get its value partially based on the same logic as another, duplicate that logic entirely and add any additional logic specific to the other variable. E.g. if you have one field that has a department as default value and another that has the department manager as default value, when setting the department manager, compute department again and than get its manager, don't try to get the department from the department field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 02:31 AM
Hi Rahul,
Write a onChange Catalog Client 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();
}
},
Please mark my answer correct and helpful if it helps.
Regards,
Sandeep Sinha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 02:37 AM
How would this be a default value in any scenario that does not involve a UI, e.g. when a B.R. creates the new record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 02:56 AM
Hi Janos,
This code will work when a form value is loaded if you want to set it using BR then.
Create a (insert or update)Business Rule on particular table.
Set condition as First Variable changes
In advance section:-
(function executeRule(current, previous /*null when async*/) {
current.second_variable=current.first_variable.dept_head;
})(current, previous);
Please mark my answer correct and helpful if it helps.
Regards,
Sandeep