- 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 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 04:54 PM
Hi Ashok,
I disabled the catalog client scripts I had in place to prepopulate the fields and added a new script like yours above and added the other additional fields and got it working!
Thank you again for all your help!
-Grace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 02:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:38 AM
https://docs.servicenow.com/bundle/istanbul-application-development/page/app-store/dev_portal/API_reference/GlideUser/concept/c_GlideUserAPI.html
the above page shows how to retrieve first name, last name etc using g_user in client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:15 AM
By the way I switch my conditions on my original post. If yes then catalog client script should not trigger and vice versa.