The CreatorCon Call for Content is officially open! Get started here.

Hide Service Portal 'Submit' button based on Form condition.

Wesley Breshear
Tera Expert

Hello,

Hopefully, this is an easy question.   I am still learning JavaScript and have no experience with AngularJS.   Anyway, I am trying to hide the 'Submit' button on a form within Service Portal.   Basically, the response on a specific question will determine if the user should be filling out a different form or not.   If true, then they are given a widget pop-up window with a hyperlink to the form that should be using.   This appears based on a UI Policy and makes the remaining fields on the form Read Only, however, the user is still able to submit the request.   I haven't been able to find a way to hide or make read only the 'Submit' button in the Service Portal.   I have found how to via CMS but not Service Portal.   There is similar request to hide the button on the Service Portal from but the button is hidden based catalog item and it appears to use AngularJS.   I can't figure out how to modify the code and then hide based on a condition.   I am not even sure if I can hide it with the Widget that I am calling by UI Policy or if I should be using a completely different process/method.   Could you help with the method and code that I should be using?

Request Form:

Request Form.jpg

Widget: (see attached for larger copy)

Widget Notification.jpg

UI Policy:

UI Policy.jpg

Thank you,

-Wesley

1 ACCEPTED SOLUTION

chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Wesley,



There are couple of options which you can try :



  1. Clone OOB "SC Catalog item" widget and add your custom validation for "Submit" button.
  2. Add onSubmit Catalog client script and you can give alert message and using "return false" statement. User will not be able to submit the request.

find_real_file.png


      3. Declare below function in your custom widget (software development tool)


                  find_real_file.png


  and call this function from UI policy whenever you want to hide. Note : you can add another function for show.


View solution in original post

13 REPLIES 13

chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Wesley,



There are couple of options which you can try :



  1. Clone OOB "SC Catalog item" widget and add your custom validation for "Submit" button.
  2. Add onSubmit Catalog client script and you can give alert message and using "return false" statement. User will not be able to submit the request.

find_real_file.png


      3. Declare below function in your custom widget (software development tool)


                  find_real_file.png


  and call this function from UI policy whenever you want to hide. Note : you can add another function for show.


Hi Chirag,



I am trying Option 3 that you recommended.   Hope this is correct?



Added this code to my Widget:


<div>


<body>


<div id="sample_check"> <font><b>You are in the incoorect form. Please click </font> <a href="https://[InstanceName].service-now.com/sp/?id=sc_cat_item&sys_id=21caf3ba0ff04700b855f08ce1050e47"><b><font color="Blue">here</font></b></a><font> to be redirected to the right form. </b></font>


</div>


</body>


</div>


<script>


  function hideSubmitBtn() {


      angular.elemement('button[name="submit"]').hide();


  }


</script>



Then add this to the UI Policy that calls the Widget.


UI Policy Script.jpg


But it is not working as intended.   Ideas or did I do your step incorrectly?



Thanks,


-Wesley


Please check Run script in Ui type field and it should be All/ Mobile or Service Portal.


find_real_file.png


Yes, tried "Mobile / Service Portal" and "All" with no success.