- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 02:51 PM
Hello,
The Dictionary Entry Override on assignment_group was done by a consultant.
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 11:22 AM
I recommend starting from scratch if you want create a new Script Include, just by entering the desired name into the appropriate field (Name😞
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 08:13 AM
You're most welcome, I'm glad it helped 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:18 PM
Wherever keyword javascript: is allowed, calling any JavaScript code - including Script Includes - is allowed. Given that OOB there already is a Script Include called Incident
(meant to be customized by clients) you could add a member to it and call that in the qualifier:
javascript: new global.Incident(current).getAssignmentGroupRefQual();
OOB (Out Of the Box) Script Include Incident
looks as below:
var Incident = Class.create();
Incident.prototype = Object.extendsObject(IncidentSNC, {
initialize: function (incidentGr) {
IncidentSNC.prototype.initialize.call(this, incidentGr);
},
type: 'Incident'
});
So pretty much empty - by adding the method proposed above it will look as below:
var Incident = Class.create();
Incident.prototype = Object.extendsObject(IncidentSNC, {
initialize: function (incidentGr) {
IncidentSNC.prototype.initialize.call(this, incidentGr);
},
getAssignmentGroupRefQual: function () {
},
type: 'Incident'
});
Of course logic needs to be added to the new method and it might look as below:
var Incident = Class.create();
Incident.prototype = Object.extendsObject(IncidentSNC, {
initialize: function (incidentGr) {
IncidentSNC.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: 'Incident'
});
In case you try this out, do make sure I did not misspell any of the group names.
By the way in this case the OR operator is replaced by a switch, though a much better solution would be to use a Data Lookup or a Decision Tables to select the right encoded query to return. Defining data in code is a very bad habit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:33 PM
Hi Janos,
I have very little on coding experience. Could you please provide step by step where I should be entering the code you suggested. I really want to learn this. Please help. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 05:02 AM
Hello @Annie,
sorry, just saw your message, however the images are not visible. Not that ServiceNow "enhanced" the editor and now it is no longer possible to paste images from the clipboard. You have to save the images to your device and attach those from there.
Supposedly it is called progress 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 04:01 PM
Hi
This is where I should go to add the logic?