If requestor tries to continue with request then Display message 'user another catalog'

sandeshraut198
Tera Contributor

Hi Community,

 

I have one requirement:-

In a catalog item, a variable set with field 'Requester location' of name-requested_for_location.

 

If requester's location is 'abc' based on the location can we give a popup message 'Please use the Teams External Calling Request instead.' and requester can not fill the next form. 

 

If user changes or rather than abc user there is no popup and user can fill the form

 

Using script include and catalog client script?

 

 

Thanks in advance.

 

 

2 REPLIES 2

Vaishnavi Lathk
Mega Sage
Mega Sage
  1. Fill out the form:

    • Name: LocationCheck
    • API Name: LocationCheck (usually auto-populated)
    • Client Callable: Checked
    • Script:
     
    var LocationCheck = Class.create(); LocationCheck.prototype = { initialize: function() { }, isRestrictedLocation: function(location) { // Assuming 'abc' is the sys_id of the location. You can also check against location name if preferred. return location === 'abc'; }, type: 'LocationCheck' };
  2. Save the Script Include.

Step 2: Create a Catalog Client Script

Next, create a Catalog Client Script that uses this Script Include to check the location and display a popup if necessary.

  1. Navigate to: Service Catalog > Catalog Definitions > Maintain Items.

  2. Open the catalog item to which you want to add this functionality.

  3. Scroll to: Related Links and select "Catalog Client Scripts".

  4. Click: New.

  5. Fill out the form:

    • Name: CheckRequesterLocation
    • UI Type: All
    • Catalog Item: [Select your catalog item]
    • Script:
     
    function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') { return; } // Get the requester's location var requesterLocation = g_form.getValue('requested_for_location'); // Call the Script Include to check if the location is 'abc' var ga = new GlideAjax('LocationCheck'); ga.addParam('sysparm_name', 'isRestrictedLocation'); ga.addParam('sysparm_location', requesterLocation); ga.getXMLAnswer(function(answer) { if (answer === 'true') { alert('Please use the Teams External Calling Request instead.'); // Disable the form (you can use g_form.setReadOnly or g_form.setVisible to hide fields) g_form.addInfoMessage('Form is disabled due to location restriction.'); g_form.setReadOnly('requested_for_location', true); // Optionally disable the submit button if required g_form.setSubmit(false); } }); }
  6. Save the Catalog Client Script.

Step 3: Test Your Implementation

Ensure you test this in a sub-production instance first:

  1. Open your catalog item form.
  2. Select a requester with the location 'abc'.
  3. Verify that the popup message appears and the form becomes disabled.
  4. Change the requester to someone with a different location and verify that the form works normally.

This setup ensures that the Script Include checks the location and the Catalog Client Script handles the user interaction by showing the popup and disabling the form as needed.

 
 

Ankur Bawiskar
Tera Patron
Tera Patron

@sandeshraut198 

you can simply use onChange client script and compare the location sysId

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader