Incident form values are clearing out once form saved
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi All,
We have worked on capturing the business domain and business function values from the CI selected on the incident form through the below link
The solution is working fine but now the values are getting cleared out once the form is saved. Help me to understand why they are clearing out.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
If the values are getting cleared out once the form is saved, then this isn't the solution and it's not working fine. Was this always the behaviour, previously unnoticed or did this just start? It seems like you're going to want to return the value of those fields from the choice fields on the CI in the Script Include, not the display value - just like you were doing in the Business Rule. In cases where the value and display value aren't the same, setting the display value will not resolve to a valid value when the record is saved. And don't append empty quotes - that's unnecessary and not the best/recommended way to ensure a string value - use .toString() when dealing with sys_id, or better yet getValue to correct both mistakes
result.domain = gr.getValue('u_business_domain');
result.function1 = gr.getValue('u_business_function');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
56m ago
you should ensure your onChange doesn't run on form load
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
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);
});
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
51m ago
Hi @Phanideepthi ,
It's clearing out on load, because you are clearing out value of fields without isLoading logic.
Add this to your client script in start :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(!newValue) {
g_form.clearValue('description');
}
}
Thanks
Anand
