- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:19 AM
How to auto populate the instance name in catalog form variable like if its dev than display Dev when QA than display QA and when prod it should display PROD
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 02:21 AM
@Ajay Singh2 You can use below client script and script include
Script include : instanceDetails
In below script you can replace the actual keyword present in your instance name like dev, qa & prod under indexOf function
var instanceDetails = Class.create();
instanceDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInstanceName:function(){
var instanceName = gs.getProperty('instance_name');
if (instanceName.indexOf('dev') > -1)
return "Dev";
if (instanceName.indexOf('qa') -1)
return "QA";
if (instanceName.indexOf('prod') > -1)
return "Prod";
},
type: 'instanceDetails'
});
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var getInstanceDetails = new GlideAjax('global.instanceDetails');
getInstanceDetails.addParam('sysparm_name', 'getInstanceName');
getInstanceDetails.getXML(InstanceName);
function InstanceName(response) {
var answer = response.responseXML.documentElement.getAttribute("answer")
g_form.setValue('instance_name', answer); // where you want to set the instance name set in that field
}
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:31 AM
Hello @Ajay Singh2
You can use this -
var instanceName = gs.getProperty('instance_name');
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:39 AM
yes i am using but issue is how to use in client script it is showing you can not use gs in client script because its server side. So please advise what to do in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:39 AM
Hi @Ajay Singh2
If it auto populate when the form loads then you can try glide Ajax
Client Script
myScriptUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:43 AM