- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2016 02:45 PM
To All Helsinki and Service Portal Users,
The Issue: Record Producer is not populating dependent variables in the Service Portal like it does in the Native UI
Assumptions: Related to the applied Client Script that isn't running in the Service Portal
Service Portal Results:
I have record producers available in the Service Catalog with dependent fields based on a client script that is currently applied. In the record producer, the "Category" is defaulted and passes to the incident ticket's Category field. The subcategory populates based on category that is defaulted, which also passes to the Subcategory field on the incident ticket. Here is how it looks in the record producer form:
Here's the behind the scene things:
Record Producer Script to pass the category and sub to the incident ticket:
Catalog Client Script applied to the record producer to filter the Subcategory based on the Category
If anyone has any idea why the client scripts applied to the record producer do not function as they should in the Service Portal, please let me know!
Also, if any further information is needed, I am more than willing to provide it
Thank you all,
-Marques
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2016 10:14 PM
Hi Marques,
The issue here is that your GlideRecord query is still synchronous and needs a call back function. When you mark it as "mobile" or "both" you have to update all your script to use the mobile version of the API.
Here is the modified script.
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('subcat');
//build a new list of dependent options
var gp = new GlideRecord('sys_choice');
gp.addQuery('dependent_value', newValue);
gp.addQuery('element', 'subcategory');
gp.query(function(gp) {
while(gp.next())
g_form.addOption('subcat', gp.value, gp.label);
});
}
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2016 12:00 PM
Pradeep,
Adjusted the code a bit and it's now working in the Service Portal.
Thanks for your help!
-Marques

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2016 06:11 PM
Thanks Marques for the update.
Can you please share modified code so that it will be helpful for others in future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2016 12:45 PM
No problem,
For some reason this line of code above was not making the subcategory dependent on the Default Value of the Category:
if(newValue == oldValue){
return
Removing this from the code allowed both the Native UI AND the Portal to populate the subcategory that was dependent on the category. Here's the code that will work for both UIs:
function onChange(control, oldValue, newValue, isLoading) {
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('subcat');
//build a new list of dependent options
var gp = new GlideRecord('sys_choice');
gp.addQuery('dependent_value', newValue);
gp.addQuery('element', 'subcategory');
gp.query(function(gp) {
while(gp.next())
g_form.addOption('subcat', gp.value, gp.label);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2017 08:14 AM
Having the same issue with the service portal. I fixed a few other dependent fields but I am having trouble with the below. I am trying to modify my code to work with the service portal except i am getting an error that I cant put a function inside a loop.
For example I call this function 3 times to populate 3 different fields but when i change
gr.query();
to
gr.query(function(gr){
I receive the error. 'dont make functions within an array' This code works in the
function Control(arrRecord, vTable, vField, fValue, blNone) {
g_form.clearOptions(vField);
var arrData = [];
for ( var a = 0; a < arrRecord.length; a++){
var grA = new GlideRecord(vTable);
gr.addQuery('sys_id',arrRecord[a]);
gr.addQuery('u_active', 'true');
gr.query();
gr.next();
varSort = gr.getValue('u_sort');
varA = gr.getValue(fValue);
arrData.push([varSort, varA]);
}
arrData.sort(sortArrayFunction);
if (blNone) {
g_form.addOption(vField, '-- None --', '-- None --');
}
for (var b = 0; b < arrData.length; b++){
g_form.addOption(vField, arrData[b][1], arrData[b][1]);
}
}
function sortArrayFunction(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? -1 : 1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 11:22 AM
The "correct answer" here is no longer correct. Although the client script was functioning properly when users we're selecting their category and subcategory from the Service Portal, once it was submitted, the subcategory was being wiped out and it was being captured as "undefined" on the incident record.
This is only the case for non-ITIL users. The issue here is that non-licensed users cannot read the value of the subcategories- Instead they need to be able to read the name. Our Service Portal was specifically designed and is used by our non-licensed user community.
We put a new solution in place and things are working again as expected. However, the engineer(s) on my team needed to write a new client script.
andypollino do you mind sharing what we came up with and correcting me on anything I missed above?
Thanks,
-Marques