Auto Populate URL Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 04:55 AM
I want to auto populate ATF Result field (URL) when ATF suite or ATF Test fields (reference) get filled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 05:07 AM
hi @Hiranmayee Moha ,
Try below script
var testCaseLink ='';
if(current.getValue('u_atf_suite')!=''){
testCaseLink =current.getValue('u_atf_suite');
}
else if(current.getValue('u_atf_test')!=''){
testCaseLink =current.getValue('u_atf_test');
}
current.setValue('u_atf_result_url', testCaseLink);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 07:45 AM
Thanks for your solution, but it's not populating the link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 08:07 AM
Try this one:
javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (control.id == 'atf_suite' || control.id == 'atf_test') {
var gr = new GlideRecord('atf_test_suite');
gr.get(newValue);
g_form.setValue('atf_result', gr.getValue('result_url'));
}
}
This script will run whenever the ATF Suite or ATF Test fields are changed. It will then fetch the corresponding URL from the ATF Test Suite table and set it as the value of the ATF Result field.
Here are the steps to implement this:
1. Navigate to System Definition > Client Scripts in ServiceNow.
2. Click on New to create a new client script.
3. Fill in the necessary fields such as Name, Table (should be the table where your ATF Suite and ATF Test fields are located).
4. Choose onChange in the Type field.
5. Paste the script in the Script field.
6. In the Field field, select ATF Suite and ATF Test.
7. Click on Submit to save the client script.
Please note that you need to replace 'atf_test_suite' and 'result_url' with the actual table name and field name in your instance. Also, this script assumes that the ATF Result field is a string field. If it's a URL field, you might need to create a URL object before setting the value.
Mark Helpful/Solution 🙂
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel