How to add "OR operator in javascript?

Annie10
Tera Contributor

Hello,

The Dictionary Entry Override on assignment_group was done by a consultant.

find_real_file.png

If Database team login, they can only see and assign incidents to Database Team and IT Service Desk Team.

We would like to add an "Or" condition in the code where if Server Team login, they can only see and assign incidents to Server Team and IT Service Desk Team.   Could someone please help? 

Thank you 

1 ACCEPTED SOLUTION

I recommend starting from scratch if you want create a new Script Include, just by entering the desired name into the appropriate field (Name😞

find_real_file.png

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

    type: 'incidentGetAssignmentGroup'
};

as you can see the system created for you the scaffolding; now you can add the desired method to it:

find_real_file.png

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

	getAssignmentGroupRefQual: function() {
        switch (true) {
            case gs.getUser().isMemberOf('Database Team'):
                return 'nameINIT Service Desk Team,Database Team';

            case gs.getUser().isMemberOf('Server Team'):
                return 'nameINIT Service Desk Team,Server Team';

            default:
                return '';
        }
    },

    type: 'incidentGetAssignmentGroup'
};

If you compare what you tried, to this "from scratch" Script Include, you will notice that the major difference is between line:

incidentGetAssignmentGroup.prototype = Object.extendsObject(incidentGetAssignmentGroupSNC, {

and line

incidentGetAssignmentGroup.prototype = {

The 1st line instructs the system to create Script Include incidentGetAssignmentGroup by "extending" the one named incidentGetAssignmentGroupSNC.

The 2nd line instructs the system to create Script Include incidentGetAssignmentGroup from scratch.

And here's the problem: the "base" Script Include incidentGetAssignmentGroupSNC does not exist. Because of this this whole code would fail.

In the original solution where the same line was:

Incident.prototype = Object.extendsObject(IncidentSNC, {

(that means create Script Include Incident by extending Script Include IncidentSNC), it worked because "base" Script Include IncidentSNC does exist (Out Of the Box).

Of course, after you create the Script Include from scratch, as described above, you will need to use it in the reference qualifier override as follows:

javascript: new global.incidentGetAssignmentGroup().getAssignmentGroupRefQual();

Let me know if you need more information.

View solution in original post

20 REPLIES 20

It looks correct, maybe just change Accessible from to All application scopes.

As for the calling part, replace your reference qualifier entirely with:

javascript: new global.Incident(current).getAssignmentGroupRefQual();

Since a picture is worth 1000 words:

find_real_file.png

Annie10
Tera Contributor

Good morning @János 

Thank you so much for helping. You suggestion work perfect.  For learning purposes, I saved the Script Include (Incident) in a different name and that did not works. 

I only could use Script Include name (Incident) to modify the code to make it works is that correct?

If not, could you please let me know where did I screwed up from the below code?

 

var incidentGetAssignmentGroup = Class.create();
incidentGetAssignmentGroup.prototype = Object.extendsObject(incidentGetAssignmentGroupSNC, {

    initialize: function(incidentGr) {
        incidentGetAssignmentGroupSNC.prototype.initialize.call(this, incidentGr);
    },

    getAssignmentGroupRefQual: function() {
        switch (true) {
            case gs.getUser().isMemberOf('Database Team'):
                return 'nameINIT Service Desk Team,Database Team';

            case gs.getUser().isMemberOf('Server Team'):
                return 'nameINIT Service Desk Team,Server Team';

            default:
                return '';
        }
    },

    type: 'incidentGetAssignmentGroup'
});

 

 

I recommend starting from scratch if you want create a new Script Include, just by entering the desired name into the appropriate field (Name😞

find_real_file.png

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

    type: 'incidentGetAssignmentGroup'
};

as you can see the system created for you the scaffolding; now you can add the desired method to it:

find_real_file.png

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

	getAssignmentGroupRefQual: function() {
        switch (true) {
            case gs.getUser().isMemberOf('Database Team'):
                return 'nameINIT Service Desk Team,Database Team';

            case gs.getUser().isMemberOf('Server Team'):
                return 'nameINIT Service Desk Team,Server Team';

            default:
                return '';
        }
    },

    type: 'incidentGetAssignmentGroup'
};

If you compare what you tried, to this "from scratch" Script Include, you will notice that the major difference is between line:

incidentGetAssignmentGroup.prototype = Object.extendsObject(incidentGetAssignmentGroupSNC, {

and line

incidentGetAssignmentGroup.prototype = {

The 1st line instructs the system to create Script Include incidentGetAssignmentGroup by "extending" the one named incidentGetAssignmentGroupSNC.

The 2nd line instructs the system to create Script Include incidentGetAssignmentGroup from scratch.

And here's the problem: the "base" Script Include incidentGetAssignmentGroupSNC does not exist. Because of this this whole code would fail.

In the original solution where the same line was:

Incident.prototype = Object.extendsObject(IncidentSNC, {

(that means create Script Include Incident by extending Script Include IncidentSNC), it worked because "base" Script Include IncidentSNC does exist (Out Of the Box).

Of course, after you create the Script Include from scratch, as described above, you will need to use it in the reference qualifier override as follows:

javascript: new global.incidentGetAssignmentGroup().getAssignmentGroupRefQual();

Let me know if you need more information.

Annie10
Tera Contributor

@János ,

You are awesome!

Thank you so much for your time and effort putting this document together so that my team and I can understand how it works.

It really helps. I learned a lot from you and the community.

I sincerely appreciate everyone assistance.