Auto Populate URL Field

Hiranmayee Moha
Tera Expert

I want to  auto populate ATF Result field (URL) when ATF suite or ATF Test fields (reference) get filled. 

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
   
   var testCaseLink = current.getValue('u_atf_suite' || 'u_atf_test');

  current.setValue('u_atf_result_url', testCaseLink);
 
})(current, previous);
 
This code is not working.
 
Kindly provide any solution.
3 REPLIES 3

Sarika S Nair1
Kilo Sage

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);

hi @Sarika S Nair1 

Thanks for your solution, but it's not populating the link.

Shaqeel
Mega Sage

Hi @Hiranmayee Moha 

 

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