- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 08:36 AM
Can anyone assist with a script to fill a Yes/No field based on another fields selection.
Background Information:
This is an Order Guide item. I am creating a catalog client script called: Set Agreement Value Based on Dept
The Order form requires fields to be filled in, like name and department. Initially the form comes up with no entries.
When I select 'Info Technology' from the reference field from the Department table , I want the field on the Order Guide Form for Confidentiality Agreement to automatically change from No to Yes.
Here is what I have tried, unsuccessfully.
Function onChange() {
var dept = g_form.getValue('department');
if(dept == 'info technology'){
g_form.setValue('agreement','Yes');
}
}
Form screen shots below: First is the Department selection fields; second is the Yes/No question I want auto populated based on the department chosen.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 12:12 PM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dept = g_form.getReference('department').name;
if(dept == 'info technology'){
g_form.setValue('agreement','Yes');
}
}
Try above script.
Regards,
Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 10:36 AM
In the order guide, create a new Catalog Client Script as below:
Name: Set Agreement Value Based on Dept
Applies to: A Catalog Item
Catalog Item: <your order guide name>
Type: onChange
Variable Name: department
Script:function onChange(control, oldValue, newValue, isLoading) {
var dept = g_form.getValue('department');
if(dept == 'info technology'){
g_form.setValue('agreement','Yes');
}
}
* assuming the variable names mentioned above are correct per your environment.
Regards,
Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 11:28 AM
This partially worked. It would not accept the words 'info technology', but if I enter in the sysid of that department is works. The department is being pulled from the Department table, so my variable in the catalog is calling a Referenced field.
Any clue why it works with sysid and not name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 11:40 AM
Yeah correct. Since it a reference field the get Value method returns sys_Id.
Try g_form.getReference ('department').name;
This should give you the selected department name.
Regards
HardikVora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 11:50 AM
Receive error
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dept = g_form.getValue('department');
// if(dept == '34bda3027c1c7400e22a4052725d4fbe'){
if(dept == 'info technology'){
g_form.getReference('department').name;
g_form.setValue('agreement','Yes');
}
}