Hide attachment from widget type variable as a checkbox

Ioannis Zapanti
Tera Contributor

Hello ,

I have an issue , i have created a checkbox variable through widget , cause i needed to include a hyperlink and on checkbox variable is not feasible.

What i try to do is when the variable is not checked hide the add attachments and when is checked show it.

Any idea on this topic?

Thanks

5 REPLIES 5

SwarnadeepNandy
Mega Sage

Hello @Ioannis Zapanti,

I am not sure what's your use-case is, but it seems a bit strange. There is much easier way to hide attachment in Service Portal https://www.servicenow.com/community/now-platform-forum/how-to-hide-quot-add-attachments-quot-button....

 

But if you insist on sticking to your use-case, then one possible way to show or hide attachments based on a checkbox variable in ServiceNow is to use a client script. A client script can run on the client side and manipulate the UI elements based on the variable value. Here is an example of a client script that hides the attachment paperclip if the checkbox variable is not checked:

 

function onLoad() {
  //Type appropriate comment here, and begin script below
  var checkbox = g_form.getValue('checkbox_variable'); //get the value of the checkbox variable
  if (checkbox == 'false') {
    document.getElementById('header_add_attachment').style.display = 'none'; //hide the attachment paperclip
  }
}

 

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy

Dear @SwarnadeepNandy  ,

Thanks for the answer. Unfortunately i have created the variable as a widget cause checkbox variable doesnt include html to insert hyperlink.

Hello @Ioannis Zapanti,

Not sure what exactly you mean.

Checkbox is a separate variable

HTML type field is a separate variable

You can create URL type variable - https://www.servicenow.com/community/developer-forum/url-variable-type/m-p/1475299

Screenshot 2023-08-28 144534.pngScreenshot 2023-08-28 144623.png