- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 09:44 AM
Hello all,
I am creating a catalog item and the first question is "Are you opening this request on behalf of someone else?" if they select No then I want the catalog client scripts to trigger because it'll prepopulate the other fields with first name, last name, employee id, etc. If they select Yes I do not want the client scripts to trigger because the user should fill out those fields manually.
Are conditions on catalog client scripts possible or would anyone recommend another best practice for this scenario?
Thanks in advance,
Grace
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 03:21 PM
Can you try this if your issue not solved yet.
I assume OPENED_BY field is there on catalog item and it already have the current user's record
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var request_behalf = g_form.getValue('request_behalf');
if(request_behalf == 'request_no'){
g_form.setValue('first_name', g_user.firstName);
g_form.setValue('last_name', g_user.lastName);
var emp = g_form.getReference('opened_by', setEmpID);
}
else
return;
}
function setEmpID(emp){
g_form.setValue('empid', emp.employee_number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:32 AM
In your IF loop, you will have to use setValue method to populate those fields.
first_name, last_name, empid are initially empty and do you want to populate them from user table with the info of user who ever is logged in ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:45 AM
Okay I'll try that. The way I currently get the user info is by referencing the opened by user see an example below
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
g_form.getReference('opened_by', setEmpID);
}
function setEmpID(ref){
g_form.setValue('empid', ref.employee_number);
}
This is what I have for each field (first name, last name, phone number, etc.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 12:03 PM
I guess you already have working solution in retrieving values, you can keep it.
To populate them into your catalog item, use setValue method in your IF loop of your first posted script.
g_form.setValue('catalog_item_variable_name', valueToSet);//valueToSet is temp variable holding the value that you want to populate into your catalog item.
Please let me know if you have any questions.
Thanks
Ashok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 02:03 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 02:18 PM
I think, this should be like,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var request_behalf = g_form.getValue('request_behalf');
if(request_behalf == 'request_no'){ // Please check if request_no is a right choice value.
g_form.setValue('first_name', g_user.firstName);
g_form.setValue('last_name', g_user.lastName);
g_form.setValue('empid', g_user.userID);
}
}