Record Producers in the Service Portal- Not Functioning Properly (Client Script Issue)

Marques2
Tera Expert

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:

find_real_file.png

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:

find_real_file.png

Here's the behind the scene things:

Record Producer Script to pass the category and sub to the incident ticket:

find_real_file.png

Catalog Client Script applied to the record producer to filter the Subcategory based on the Category

find_real_file.png

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

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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.


View solution in original post

11 REPLIES 11

Community Alums
Not applicable

Did you set you catalog client script UI type to 'Both'?



Check here for some good info:



documentation/client_scripting.md at master · service-portal/documentation · GitHub



Cheers,



Tim


Community Alums
Not applicable

Sorry, just looked at your image above, noticed that it is set correctly...


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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.


Hey Pradeep,



Thanks for the reply. I attempted to apply the script above but it broke the filtering in the Native UI. The subcategory is not longer dependent on the value the category displays. Now all subcategory options are available. I'm not sure what is making it do this but it's not working as expected.



Any other ideas?


-Marques