- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 05:44 AM
Please suggest how to use script include in filter condition under change approval policy. I need to get values dynamically populated.
This is my script. Where can I add arguments (intended groups) to this script and how can the mail ID be returned
var checking_user_is_part_of_specific_Group = Class.create();
checking_user_is_part_of_specific_Group.prototype = (AbstractAjaxProcessor, {
initialize: function() {
answer = ifScript();
function ifScript() {
var ABC= gs.getProperty('ABC.grp');
var BCD= gs.getProperty('BCD.grp');
var DEF= gs.getProperty('DEF.grp');
var REH= gs.getProperty('REH.grp');
var answer;
if (gs.getUser().isMemberOf(ABC) || gs.getUser().isMemberOf(BCD)|| gs.getUser().isMemberOf(DEF)|| gs.getUser().isMemberOf(REH)){
return "yes";
} else {
return "no";
}
}
type: 'checking_user_is_part_of_specific_Group';
}
});
I need to use this script here. Please help me to understand how it can be done.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 05:51 AM
Hi Vignesha,
Please try
javascript: new scriptIncludeName.functionName();
OR
javascript: scriptIncludeName.functionName();
Mark Correct and helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 05:53 AM
HI @Vignesha Priya ,
I trust you are doing fine.
To use a script include in a filter condition under change approval policy, you can use the GlideFilter API to dynamically populate values. Here's an example:
var myScriptInclude = new MyScriptInclude(); // Instantiate your script include
var myList = myScriptInclude.getValues(myArgument); // Call a function in your script include to get values
var filter = "approval = true"; // Your filter condition
var glideFilter = new GlideFilter(filter); // Instantiate the GlideFilter object
var encodedQuery = glideFilter.getEncodedQuery(); // Get the encoded query
var gr = new GlideRecord('change_request'); // Instantiate the GlideRecord object
gr.addEncodedQuery(encodedQuery); // Add the encoded query to the GlideRecord object
gr.query(); // Execute the query
while (gr.next()) {
// Your logic here
}
In the above code, MyScriptInclude is the name of your script include, myArgument is the argument you want to pass to the getValues function, and approval = true is the filter condition. You can modify the filter condition as needed.
Regarding your script, you can add arguments to your script include by adding them as parameters to your function, like this:
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {},
getValues: function(argument1, argument2) {
// Your logic here
}
}
To return the mail ID from your script, you can modify your ifScript function to return the mail ID instead of a string. Here's an example:
function ifScript() {
var ABC = gs.getProperty('ABC.grp');
var BCD = gs.getProperty('BCD.grp');
var DEF = gs.getProperty('DEF.grp');
var REH = gs.getProperty('REH.grp');
var answer;
if (gs.getUser().isMemberOf(ABC) || gs.getUser().isMemberOf(BCD) || gs.getUser().isMemberOf(DEF) || gs.getUser().isMemberOf(REH)) {
var email = gs.getUser().getEmail();
return email;
} else {
return "";
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 11:42 PM
Thank you so much !!!
Firstly,
I am already having script include function with ifScript inside. Is that correct?
The function that you have provided first is client script, correct?
The next one is the script include where you have getvalues function. I think my ifscript logic needs to be inserted here,crct? I want this scriptinclude function to be used as part of
How can I that be achieved. beacuse filter condition i give inside that variable dedicated..I have logic inside ifscript function..Then I have no logic for
while (gr.next()) { // Your logic here }