Script include return value not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:08 PM
Hi All,
I am modifying a catalog in which I have
Variable 1: List collector variable name "Application" in which i am gliding "cmdb_ci_business_application".
Variable 2: Environment which is select box having choices with, production, DEV, QA so on..
The requirement is based on the variable 1 and 2 the variable 3 should populate the value with certain condition.
The 3rd variable "Application server" is list collector which is to query value from custom table "u_m2m_servers_applications". The values from variable 1 and 2 to be passed to M2M table and we have to pick the related server.
For instance in the M2M table iam querying application with environment there will be some 5 values which will be matching, and will be showing in list collector of variable 3. I dont want to list down the retired / decomm.
The challenging is the server should not be retired or decommission.
From the reference qualifier we can able to pass the value of variable 1 and 2. But we cannot put the condition for DOTWALKING the server status information.
So i tried using a script include to fetch the value. But i am stuck with return value how to pass it back to variable. Please find my script below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:21 PM - edited 10-24-2023 01:25 PM
Hi @AnandKumar1 ,
You have to write client script [ onChange ] on Environment variable and use the GlideAjax to call script include method and get the result populated in the 3rd variable.
Refer this link as example
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:31 PM
HI Ashish,
Since i am able to pass the value directly. You mean for storing the value from script include to use onChange client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:53 PM - edited 10-24-2023 01:54 PM
Yes, i mean the same but let's make some changes on the current code and try it.
create a array variable before "if (m2m.next()) {" and add all result using the .push() method and return the same array variable.
I don't understand, why you are querying the "cmdb_ci_server" just for retire/decommission status, when the table "u_m2m_servers_applications" has reference of application, and you already using the dot walking for environment value check ..do the same for retire & decommission.
var ServerApplications = Class.create();
ServerApplications.prototype = {
initialize: function() {},
relatedServer: function(application, environment) {
gs.log('AK function call');
var serverSysId = null;
gs.log("AK function inner test param" + application + "*" + environment, "Serverapp");
var result = [];
var m2m = new GlideRecord('u_m2m_servers_applications');
m2m.addQuery('u_application', application);
m2m.addQuery('u_application.environment', environment);
m2m.addQuery('u_application.retire', false);
m2m.addQuery('u_application.decommision', false);
m2m.query();
// use while if more than 1 record expected
if (m2m.next()) {
result.push( m2m.sys_id );
}
return result;
gs.log("AK function false value " + serverGr, "Serverapp");
},
type: 'ServerApplications'
};
Please check for any syntax error.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 10:51 PM
Hi Ashish,
The reason i am seperately gliding the windows server is, in the M2M table the there is an attribute server that servers only i have to display with condition not retired.
The servers are reference and related to win_server table. So i am taking another logic with it.
Thanks.