- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 01:06 AM
Hi Developers,
I am writig a Script include to fetch Environment variable on a form with below condition.
I have a catalog form where an Application name field exist and based on application name i want to fetch environment type.
So i have created a script include in which i am querying this table "azure_enviro_application" because Application field and Environment field both are exist on this table form .
Both field are refrence field from diffrent tables .
**********************************************************************************
Client Script-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ajaxENV = new GlideAjax('Check_ENV');
ajaxENV.addParam('sysparm_name', 'Envforapplication');
ajaxENV.addParam('sysparm_appname', g_form.getValue('ApplicationName'));
ajaxENV.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = response.responseXML.getElementsByTagName("result");
var valueofENV = result[0].getAttribute("u_azure_environment_type");
// g_form.setValue(' Environment', valueofENV);
alert(valueofENV);
}
*****************************************************************
Script Include-
var Check_ENV = Class.create();
Check_ENV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Envforapplication: function(){
var ENV;
var appname = this.getParameter('sysparm_appname');
// Fetching Sys_id of application name from form //
var Sys_IDforapplication = gr.addQuery('sys_id', appname);
// Fetching Sys_id of application name from azure_enviroment_application"table //
var grenv = new GlideRecord('azure_enviroment_application');
var Second_Sys_ID = grenv.getValue('u_azure_application');
grenv.query();
if(Sys_IDforapplication == Second_Sys_ID){
ENV = grenv.getValue('u_azure_environment_type');
result = this.newItem("result");
result.setAttribute("u_azure_environment_type",ENV);
}
return result;
},
type: 'Check_ENV'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:01 AM
Try the below Client & Script Include scripts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajaxENV = new GlideAjax('Check_ENV');
ajaxENV.addParam('sysparm_name', 'Envforapplication');
ajaxENV.addParam('sysparm_appname', g_form.getValue('ApplicationName'));
ajaxENV.getXMLAnswer(getResponse);
function getResponse(answer) {
alert(answer);
}
}
var Check_ENV = Class.create();
Check_ENV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Envforapplication: function() {
var ENV;
// Fetching Sys_id of application name from form //
var app_sysId = this.getParameter('sysparm_appname');
// Fetching Sys_id of application name from azure_enviroment_application"table //
var grenv = new GlideRecord('azure_enviro_application');
grenv.addQuery('u_zaure_application', app_sysId);
grenv.query();
if (grenv.next()) {
ENV = grenv.getValue('u_azure_environment_type');
}
return ENV || '';
},
type: 'Check_ENV'
});
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:01 AM
Try the below Client & Script Include scripts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajaxENV = new GlideAjax('Check_ENV');
ajaxENV.addParam('sysparm_name', 'Envforapplication');
ajaxENV.addParam('sysparm_appname', g_form.getValue('ApplicationName'));
ajaxENV.getXMLAnswer(getResponse);
function getResponse(answer) {
alert(answer);
}
}
var Check_ENV = Class.create();
Check_ENV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Envforapplication: function() {
var ENV;
// Fetching Sys_id of application name from form //
var app_sysId = this.getParameter('sysparm_appname');
// Fetching Sys_id of application name from azure_enviroment_application"table //
var grenv = new GlideRecord('azure_enviro_application');
grenv.addQuery('u_zaure_application', app_sysId);
grenv.query();
if (grenv.next()) {
ENV = grenv.getValue('u_azure_environment_type');
}
return ENV || '';
},
type: 'Check_ENV'
});
Thanks & Regards,
Vasanth