Script Include in Reference Qualifier

IzaqueN
Tera Contributor

Hello. I'm doing an exercise and need to do this: "I, as an administrator, want the students to be able to enroll only once in each training".

Here's my solution: 
A script include:

var SharkLearningUtils = Class.create();
SharkLearningUtils.prototype = {
    initialize: function() {},

    singleEnroll: function() {
        var trainingsNotToBeShown = [];

        var grEnrollment = new GlideRecord("x_1593181_shark_0_enrollment");
        grEnrollment.addEncodedQuery("opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^state!=4");
        grEnrollment.query();

        while (grEnrollment.next()) {
            trainingsNotToBeShown.push(grEnrollment.training.sys_id.toString());
        }

        var trainingsToBeShown = [];

        var grTrainings = new GlideRecord("x_1593181_shark_0_training");
        grTrainings.query();

        while (grTrainings.next()) {
            if (trainingsNotToBeShown.indexOf(grTrainings.sys_id.toString()) == -1) {
                trainingsToBeShown.push(grTrainings.sys_id.toString());
            }
        }

        return "sys_idIN" + trainingsToBeShown.join(",");
    },

    type: "SharkLearningUtils"
};

A reference qualifier in a question in a Record Producer:
javascript: new x_1593181_shark_0.SharkLearningUtils().singleEnroll();

I have tried so many times to make this work, and can't find the error, can you help me?
2 REPLIES 2

Sujatha V M
Kilo Patron
Kilo Patron

@IzaqueN 

 

1. Did you try to put a log within the script include to check if its getting invoked to return the value?

 

2. Is the client callable set to true for your scenario? 

SujathaVM_0-1738223066504.png

3. Are you able to get the return value in script include?

 

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Ankur Bawiskar
Tera Patron
Tera Patron

@IzaqueN 

on your record producer are you having any reference variable?

We don't know the complete details so can't help

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader