Modal pop-up to select a value from list (service portal) .... how to?

Zod
Giga Guru

Hi there,

we would require a user to select a value from a referenced record via a modal pop-up trying to submit a request in the service portal. How to archive this?

The use case is, that a value is to be picked from a references table - but as this value might not be valid anymore when submitting the request, the idea is to move the value selection to the end of the requesting step right before submitting the request.

Idea is to have a catalog client script on submit to show a popup to the user and let him select a referenced value from a CI table ... 

Possible? 

Thank you!

3 REPLIES 3

Josh Virelli
Tera Guru

Hi Zod,

The modal window may be possible, however I think it would be far more appropriate to use an Advanced Reference Qualifier, a Script Include, and a UI Policy to solve this.

1) Create a UI Policy that checks that every variable is populated that limits the possible choices for the reference variable. i.e. var_name [is anything] AND
var_name2 [is anything] etc.

2) Create a UI Policy Action for the reference variable, that is visible and mandatory if true and Reverse if false is checked.

3) On the reference variable, under Type Specifications, change the Use reference qualifier field to "advanced", and replace the script below with the name of the Script Include, script include functions, and the variables values you need to pass into this function to create your query.

find_real_file.png

4) Your Script Include should return an Encoded Query string that will limit the choices of the Reference variable. Not only is this an easier solution, it will also allow the user to make changes to the form and then the reference variable will update.

For more on Advanced Reference Qualifiers, check out these links and the Community:

https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-scri...

https://community.servicenow.com/community?id=community_question&sys_id=ae650faddbd8dbc01dcaf3231f96...

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/script/server-scripting/concept/...

Hi.

Yes this might work - BUT the issue is, that I want this to happen only within the last step of the request - so AFTER the order button has been pushed.

If we can not do this right before submitting, we run into additional efforts to do validations over and over again ... what is tricky in our case ... 

johansec
Tera Guru

If you absolutely have to do this you can but its a bit of work.

 

You will have to clone the form widget on that page.

If this is a catalog item it should be using the widget "SC Catalog Item"

 

So clone it and replace it on the page or place it on a new page. 

Make sure everything works as is and ensure your clone is showing.

 

Then you will have to find out what function is called when submitted.

  I think it would be this one

$scope.triggerOnSubmit = function(){
		$scope.data.sc_cat_item.item_action = "order";
		$scope.data.sc_cat_item.quantity = c.quantity;

               // RIGHT HERE IS PRESUBMIT
		if (g_form)
			g_form.submit();
	}

 

That is where you would have to open your modal.

To do this, I would inject $uibModal in the top of your client script. This allows you to use a bootstrap modal. There are tutorials out there on how to use this.

 

In the template for that modal have whatever you need for a user to select the value you need them to.

Bind this value to a $scope var 

Close the modal.

Update g_form.

Miminc the last part of the triggerOnSubmit funciton to then go ahead and submit the form. 

 

You may want to make a custom page for this one widget since im pretty sure this does not apply to all of your catalog items. 

 

This is going to be a big pain but possible.

 

If anyway possible, I would highly reccommend using Josh Virelli – CloudPires solution. 

 

Good Luck

 

Modal tutorial

https://serviceportal.io/modal-windows-service-portal/