- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
We have two fields Business domain and Business function on the incident form as shown in the image. Now we are working on getting the values populated on the form when a CI is selected. We have written before insert business rule with the following script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Phanideepthi ,
Your client script looks good but small issue in script include
getValues: function() {
gs.log('function');
var ciSysId = this.getParameter("sysparm_ci");
var result = {};
var gr = new GlideRecord('cmdb_ci');
if (gr.get(ciSysId)) {
result.domain = gr.u_business_domain.getDisplayValue() + ""; // getDisplayValue you are using small D in display
result.function1 = gr.u_business_function.getDisplayValue() + "";
}
gs.log("Check Return = " + JSON.stringify(result));
return JSON.stringify(result);
},
type: 'GetBusinessDetails'
});Also add alert in Client script
function onChange(control, oldValue, newValue) {
if (!newValue) {
g_form.clearValue('u_business_domain'); // Your field backend value
g_form.clearValue('u_business_function'); //Your field backend value
return;
}
var ga = new GlideAjax('GetBusinessDetails');
ga.addParam('sysparm_name', 'getValues');
ga.addParam('sysparm_ci', newValue); // new Value is your CI field value sysId
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
alert(obj.function1);
alert(obj.domain); // if you alert obj it will pass object object you can do JSON.stringify(obj) or dot walk
g_form.setValue('u_business_domain', obj.domain);
g_form.setValue('u_business_function', obj.function1);
});
}Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Phanideepthi ,
Issue is you created Business Rule, BR will run when it got some trigger condition, as you mention before insert, but you want the value will auto populate when you select the field.
So in this case please create On-Change Client script, table - Incident, field - CI Field and add below script
function onChange(control, oldValue, newValue) {
if (!newValue) {
g_form.clearValue('u_business_domain'); // Your field backend value
g_form.clearValue('u_business_function'); //Your field backend value
return;
}
var ga = new GlideAjax('GetBusinessDetails');
ga.addParam('sysparm_name', 'getValues');
ga.addParam('sysparm_ci', newValue); // new Value is your CI field value sysId
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
g_form.setValue('u_business_domain', obj.domain);
g_form.setValue('u_business_function', obj.function);
});
}
Now Create Script Include - GlideAjax Checked and add below script
var GetBusinessDetails = Class.create();
GetBusinessDetails.prototype = {
initialize: function() {},
getValues: function() {
var ciSysId = this.getParameter("sysparm_ci");
var result = {};
var gr = new GlideRecord('cmdb_ci_service_discovered');
if (gr.get(ciSysId)) {
result.domain = gr.u_business_domain + "";
result.function = gr.u_business_function + "";
}
return JSON.stringify(result);
},
type: 'GetBusinessDetails'
};
Let me know if you need more help!
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Sarthak Kashyap ,
Thanks for your reply. I am getting undefined value as shown in the image when using the above script.
Note: we do have dropdown values in business domain and function and need to be selected from there instead of creating new values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Phanideepthi ,
Try to add logs in your script include and add alert in your callback function in client script and check where you are getting the undefined or send me the script
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Here is the script and alert
