- 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 09:52 AM
Hi Grace
Absolutely, you can write onChange catalog client script on your variable (example:variable_name). Retrieve the value of the field using g_form.getValue("variable_name") and populate required fields as necessary if the value is YES.
Thanks
Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 10:20 AM
Thanks Kumar this is very helpful! So I in this onChange catalog client script I would include all the fields I am trying to populate or would I have to create one for each variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 10:33 AM
Grace, one Catalog Client script would be enough to populate as many fields as you want
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:15 AM
Got it, thank you! I have the following script would you mind reviewing? I feel like I'm confusing myself because I had onChange catalog client scripts to populate each field but now that I'm creating one based on the condition I'm not sure if I need those individual scripts?
Variable name: request_behalf
Type: onChange
Script:
function onChange(control, oldValue, newValue, isLoading) {
var request_behalf = g_form.getValue("request_behalf");
if (request_behalf == 'request_no')
{
g_form.getValue("first_name");
g_form.getValue("last_name");
g_form.getValue("empid");
}
if(request_behalf == 'request_yes')
return false;
}