How do I debug a Record Producer client script?

Dave49
Giga Contributor

I have a Service Portal option that opens a Record Producer to create an incident record.

On the record Producer, there is a Catalog Client script:

find_real_file.png

What we want to happen is that the Sub Category Power BI option is removed as shown.

The script works sort of. If you select the correct value in the Category, the option list is assigned to the Sub Category but, the Power BI option is present.

If you select any of the options, the Power BI option is then removed from the list.

If we change the Variable name from subcategory to category, the script does not work at all. It runs which we know from having placed an alert in it. But the removeOption function doesn't remove the Power BI option.

I have 2 questions:

1) How do I debug the Service Portal?

2) What is the sequence of events on the Record Producer, i.e. which of the following executes first, second, etc...

The scripts on the variables;   The Catalog UI Policies;  The Catalog client scripts.

find_real_file.png

The system acts as though the catalog client script fires and then the Sub Category variable's Type Specifications Reference qualifier script runs.which overwrites the catalog client script.

Then, when you actually select something from the Subcategory field, the script runs again and removes the Power BI option.

FYI:

We tried to modify this using a Catalog UI Policy with On Load checked and unchecked and putting just the removeOption from the script above in the Execute if true script option with an alert in both options. That didn't work either.

find_real_file.png

find_real_file.png

On the When to Apply tab note 3 at the top says: "The field specified in the catalog UI policy is present on the specified ctalog item" . Because of the note, I created the UI Policy Action because it is the only place I could find to specify a field. Is this note refering to the field used in the script?

It seems to me that the UI Policy is the better way to do this, but it is not working at all.

Any and all help will be greatly appreciated.

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

This script is only set to run when subcategory changes, which isn't what you want - the choice list should be set prior to the user interacting with that variable.  It sounds like you're saying that the subcategory list is dependent on the selection of Category.  If that's the case then you must already have an onChange catalog client script on Category that is adding, and/or removing or clearing options.  Assuming Company is intended to be set prior to subcategory (and category) you should add the removeOption with the if statement to your Category onChange script.  You'll want one catalog client script that effects subcategory.  Make sure there are no other active catalog UI policies or catalog client scripts that effect the subcategory variable.  Also, removeOption only works on Select Box type variables, which don't have Type Specification Reference qualifiers, so your statement about that script overwriting this one is confusing.  Subcategory has the Type of Select Box, correct?  And there is not a Reference qualifier on the Type Specifications?  Are you using a Choice table and field, or Question Choices to populate the choice list, or is this only being done through catalog client script(s)?

Alok Das
Tera Guru

Hi Dave,

I believe you want the option "Power BI" to be only available for 3 company and for others it will be removed from the choice. If my understanding is correct could you please give a try with below script.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var comp = g_form.getValue('company');
    alert('Company sys_id: ' + comp); //remove this line if script works fine
    if (comp == 'sys_id1' || comp == 'sys_id2' || comp == 'sys_id3') { //enter the correct sys_id of company.
        alert("Script entered IF"); //remove this line if script works fine
        g_form.addOption('subcategory', 'Value of Power BI', 'Label of Power BI');
    } else {
        alert("Script entered else"); //remove this line if script works fine
        g_form.removeOption('subcategory', 'Value of Power BI'); //make sure that the field name is "subcategory" and the backend name of the choice is correctly mentioned.
    }
}

 

I have added alert in the script to debug and one issue I noticed that in your script if condition is defined and no else condition so if your script works then you might encounter a new issue that if any other company is selected first then the option will be removed but if again the option is changed it will not satisfy the if condition and since there is no else the option will not be added so I changed the logic a bit.

Also, make sure that you are entering the correct back-end value of choice "Power BI".

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok