How to set choice values on form

Nag9
Tera Expert

Hi All, I have below business requirement

In my catalog form i have two variables 

1. Target number - which is reference to target table

2. Complaint - as select box(yes/no)

 

 if we select a target number in first variable as TGT1234(inside that " TGT1234 " form we have a field called "complaint " with data as 'test complaint')

 My question is 

if i select a target number in first variable and that number form has complaint field data i need to set the second variable complaint as yes and it should be read only.

 

if i select a target number in first variable and that number form has no complaint field data i need to set the second variable complaint as No and it should be read only.

 

 

How can we achieve this

 

 

 

 

 

14 REPLIES 14

Hi Ankur

 

tried with below script in ui policies with some filter conditions

 


var number = g_form.getReference('target_number', doAlert);

function doAlert(number) {
if(number.u_complaint_num!=''){
g_form.setValue('u_complaint', 'yes');
g_form.setReadOnly('u_complaint',true);
}
else{
g_form.setValue('u_complaint', 'no');
}
//Type appropriate comment here, and begin script below

}

 

 

above script is setting NO value into second variable if the selected target record has no complaint data in the form

 

where as 

 

above script is not setting YES value into second variable if the selected target record has complaint data in the form

 

 

try this and share

var number = g_form.getReference('target_number', doAlert);

function doAlert(number) {
    alert(number.u_complaint_num); // check what comes here
    if(number.u_complaint_num!='' && number.u_complaint_num != undefined){
        g_form.setValue('u_complaint', 'yes');
        g_form.setReadOnly('u_complaint',true);
    }
    else{
        g_form.setValue('u_complaint', 'no');
    }
    //Type appropriate comment here, and begin script below

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Nag

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vishnu Prasad K
Giga Guru

Hi Nag,

 

You can achieve it using below 2 methods

1. Catalog client script and a script include

2. Catalog client script with a getReference() function.

 

It's best to create a script include and call it in catalog client script using GlideAjax.  In the script include you will be checking if the 'Complaint' field has a value or not. 

Thankyou Vishnu,

 

Could you please provide the sample script as I'm not pretty good at script