- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 02:03 AM
Hi All,
I have a requirement like the record producer fields should be auto filled based on the first two field selection.
E.g. I have to two field business function and business process so once if user select those fields and if already there is a record existed with same business function and business process in the table then all the remaining fields should be auto populated same as already existing record how to do this if anyone has pointers and scripts for this, please do share.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 11:54 PM
Hi @Kruthik M Shiva,
Hope you are doing well and Glad to see that you are following my answers and solutions and happy to assist you.
Proposed Solution
As a solution, you need to modify above script as same as mentioned below and I tried it on my Personal Developer Instance to get the desired outputs. Hope this will work for you now and let me know if any other help needed. Attaching screenshots for the reference.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('u_category') != '') {
if (newValue != '') {
var val = confirm('If you want to copy same fields?');
if (val) {
var ga = new GlideAjax('global.AutoPopulateIncidentDetails');
ga.addParam('sysparm_name', 'incidentDetails');
ga.addParam('sysparm_category', g_form.getValue('u_category'));
ga.addParam('sysparm_sub_category', newValue);
ga.getXML(populateDetails);
function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var ans = JSON.parse(answer);
g_form.setValue('short_description', ans[0]);
g_form.setValue('state', ans[1]);
}
}
else{
alert('You cancel the Auto Population Fields Request.');
}
}
} else {
alert('Kindly fill category first.');
g_form.setValue('u_sub_category', '');
}
}
Sample Outputs: -
After Pressing Ok: - Fields will be auto populated.
After Pressing Cancel: - Field will not be auto populate and 1 alert message will be displayed.
If you find this information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.
Thanks :)
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:02 PM
Hi @AakashG2703 ,
Just wanted to add one extra thing that if business function and business process matches it should ask for confirmation message like if you want to copy same fields if they clicked ok then only it should auto populate else it should not be. Could you please help me what changes needs to be done for this?
Thanks,
Kruthik Shivaprasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 11:54 PM
Hi @Kruthik M Shiva,
Hope you are doing well and Glad to see that you are following my answers and solutions and happy to assist you.
Proposed Solution
As a solution, you need to modify above script as same as mentioned below and I tried it on my Personal Developer Instance to get the desired outputs. Hope this will work for you now and let me know if any other help needed. Attaching screenshots for the reference.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('u_category') != '') {
if (newValue != '') {
var val = confirm('If you want to copy same fields?');
if (val) {
var ga = new GlideAjax('global.AutoPopulateIncidentDetails');
ga.addParam('sysparm_name', 'incidentDetails');
ga.addParam('sysparm_category', g_form.getValue('u_category'));
ga.addParam('sysparm_sub_category', newValue);
ga.getXML(populateDetails);
function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var ans = JSON.parse(answer);
g_form.setValue('short_description', ans[0]);
g_form.setValue('state', ans[1]);
}
}
else{
alert('You cancel the Auto Population Fields Request.');
}
}
} else {
alert('Kindly fill category first.');
g_form.setValue('u_sub_category', '');
}
}
Sample Outputs: -
After Pressing Ok: - Fields will be auto populated.
After Pressing Cancel: - Field will not be auto populate and 1 alert message will be displayed.
If you find this information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.
Thanks :)
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 03:25 AM
Hi @AakashG2703 ,
I tried with your given code but it not working for me. In my case business function is choice field and process are text field though I have given the same text it didn't worked for me.
Script Include:
Thanks,
Kruthik Shivaprasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 03:56 AM
Hi @Kruthik M Shiva,
Kindly try to debug your code by using an "alert()" function or method in your client script like: -
- Check whether you are able to get the value of Business Function and Business Process using alert().
- Further check whether you are able to make a right query and getting the data or not in an array. Try to use gs.log().
- Further check whether you are able to receive any value from Script Include or not by using an alert().
These are some point that will be helpful for you to debug your code mentioned above. Let me know if you still need some help and try to provide some screenshots of the output by using above statements so that I will be able to rectify the issue or challenge in scripting or what we are missing.
If you find any information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.
Thanks :)
Aakash Garg
ServiceNow Developer