Service Portal Mandatory Fields

jamesk-apm
Kilo Contributor

Hi All,

We are running Helsinki patch 5 and have started to look at implementing the shopping cart in the Service Portal. The problem we are having is trying to make fields mandatory. See screenshot below showing the field we would like to make mandatory:

Service Portal Mandatory Field.png

We have client script code that is set to run for both mobile and desktop set for the UI type. This works in the Service Catalog but not in the Service Portal when attempting a checkout without a Business Justification set. I am assuming I need to set this in the client script of the widget in question, just not sure where to start with the code for this.

Does anyone have some links to good resources to help with developing widgets?

Thanks

James

1 ACCEPTED SOLUTION

mandle
Mega Guru

James,



I'd first like to caution you about leveraging the Helsinki Patch 5 shopping cart widgets. We're not sure why they were included since the Shopping Cart and Bundles in Service Portal are most likely not being released until Istanbul.



That said, it appears from your screenshot that you are trying to make the relabeld Special Instructions field, "Business Justification", field mandatory in the "SC Shopping Cart" widget.


The HTML for that field is in the sp_ng_template called "large_shopping_cart.html" record:


Since you've already taken ownership of the "large_shopping_cart.html" template record you could add in a "placeholder" value that also draws attention to the mandatory nature of this field.



You could add the following to the "Client Script" on the "SC Shopping Cart" widget


Between Lines 13-14 add the following:



if (c.additionalDetails == '') {


  1.         spUtil.addErrorMessage('Business Justification is required before Checkout. Thank you!');                                          
  2.         return;
    }                                  


And you could add some CSS to the "SC Shopping Cart" widget to draw attention to the mandatory "Business Justification":


I'm adding minimal CSS here but you could go further...



.special-instructions-details label {


  color: tomato;


}




Results:



Screen Shot 2016-11-15 at 11.49.21 AM.png



Screen Shot 2016-11-15 at 11.49.29 AM.png


View solution in original post

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi James,



If you're using a catalog client script to make that field mandatory in your catalog you should also be able to do that in the service portal. I'm wondering if somewhere in your client script you're using something unsupported in SP so the script isn't working. Could you post your client script?


Kedar Pittman
Giga Guru

Either one of these should work.



function onLoad() {


    //Type appropriate comment here, and begin script below


            g_form.setMandatory('your_variable_goes_here' , true);


}






function onSubmit() {


    //Type appropriate comment here, and begin script below


            g_form.setMandatory('your_variable_goes_here' , true);


}





http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0


mandle
Mega Guru

James,



I'd first like to caution you about leveraging the Helsinki Patch 5 shopping cart widgets. We're not sure why they were included since the Shopping Cart and Bundles in Service Portal are most likely not being released until Istanbul.



That said, it appears from your screenshot that you are trying to make the relabeld Special Instructions field, "Business Justification", field mandatory in the "SC Shopping Cart" widget.


The HTML for that field is in the sp_ng_template called "large_shopping_cart.html" record:


Since you've already taken ownership of the "large_shopping_cart.html" template record you could add in a "placeholder" value that also draws attention to the mandatory nature of this field.



You could add the following to the "Client Script" on the "SC Shopping Cart" widget


Between Lines 13-14 add the following:



if (c.additionalDetails == '') {


  1.         spUtil.addErrorMessage('Business Justification is required before Checkout. Thank you!');                                          
  2.         return;
    }                                  


And you could add some CSS to the "SC Shopping Cart" widget to draw attention to the mandatory "Business Justification":


I'm adding minimal CSS here but you could go further...



.special-instructions-details label {


  color: tomato;


}




Results:



Screen Shot 2016-11-15 at 11.49.21 AM.png



Screen Shot 2016-11-15 at 11.49.29 AM.png


Hi Jeremy,



When I am trying to add the same code for reference field it is not working. My use case is that I have created three new fields like approving manager, cost center, department.



Approving manager will be autopopulated based on the user, if some user doesn't have manager, then in that case the field will be empty and whenever the values changes to empty, we have to show this error message.. Can you help me