How to Show/Hide URL Field When Required

msekla
Tera Contributor

I currently have a hidden URL field made and I want it to appear in my Generic Request form once I select a Configuration Item that has a specific URL value I put in the CMDB.

If the chosen Configuration Item has the "URL required" field set to "yes" on the CI listing, then:
1. Show the "URL" field on the Generic Request form (i.e. make it visible)
2. Make the "URL" field mandatory on the Generic Request form

 

I have attached a snippet of what I have so far and I don't know why it's not working as in when I select a Configuration Item that has the URL value that I put in the CMDB, that the script looks for, it should then make the URL field appear on my form and make it mandatory.

Please help and let me know what I should do in detail. Thank you.

1 ACCEPTED SOLUTION

@msekla , it might be because of setVisible so try replace this with setDisplay() 

 

g_form.setDisplay('url',true);

 

replace in both if and else if 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

View solution in original post

26 REPLIES 26

@msekla , in your code URL field is appearing because you have directly setted it, you are not at all checking the script include return value which is ans, 

 

Try using my code and add the alerts back and make sure in your cmdb_ci record for which you are trying you have checked the URL required to true and then check the alert if answer is true it will show you the url field if answer is false it will hide the URL field 

This is my code right now and the cmdb side looks good so I don't know why it's not working

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.setVisible('ccw_url', false);
        return;
 
    }
 
var sysid = g_form.getValue('cmdb');
var url = new GlideAjax('getUrlRequired');
url.addParam('sysparm_id',sysid);
url.getXML(getResponse);
 
}
 
function getResponse(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
alert('answer' + ans);
if(ans == true || ans == 'true')
{
g_form.setVisible('ccw_url',true);
g_form.setMandatory('ccw_url',true);
}
else if(ans == false || ans == 'false'){
g_form.setMandatory('ccw_url',false);
g_form.setVisible('ccw_url',false);
 
}
 
}

@msekla ,

 

in client script calling script include function is missing 

after this line ' var url = new GlideAjax('getUrlRequired');  '

 

url.addParam('sysparm_name','getUrl');

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

I added it back in and still nothing, is it supposed to be 'getURL' or my own thing?

@msekla it should be the function name which you have used inside your script include 

 

you have also used the same one 

getUrl: function() {