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  could you please copy paste the entire thing and just change the backend names the field if you want i can add comments where you have to change ..

 

and cmdb_ci table has child table so dont create URL required on child table directly in cmdb_ci create the URL Reuired field 

 

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

Regards,

Swathi Sarang

I did copy n paste the whole thing and just changed some variables so it can match what I have in the backend, but still nothing. Do you have discord?

@swathisarang98 I got everything to work and I used your exact code but for some reason I am now having this weird gap in my form where the URL is supposed to appear. It seems to be making a placeholder for the URL field but I want it to just appear and push all of the other fields down to make room for the URL field as it should be normally. A screenshot of the issue is attached.

@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

 

Thank you it finally worked