If the Requested for user Location & Country is not India, do not allow to submit the catalog item.

Omkarbh97
Tera Contributor

If the Requested for user Location & Country is not India, do not allow to submit the catalog item and show error message and if the Location & Country is India then catalog item is submitted.

5 REPLIES 5

Narsing1
Mega Sage

Instead of validating on submit, its better to filter the Requested for variable via Reference Qualifier condition.

Narsing1_0-1704388600999.png

 

Thanks,

Narsing

Hello, Narsing1

I don't have to use reference qualifier,

I have to complete this task using catalog client script.

Do like this

Script Include (Client Callable): userUtils

var userUtils = Class.create();
userUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	isIndia: function() {
		var uid = this.getParameter("sysparm_uid");
		var gruser = new GlideRecord("sys_user");
		gruser.get(uid);
		if (gruser.location.country == "India")
			return "yes";
		else 
			return "no";
	},
    type: 'userUtils'
});

Onsubmit Client Script

function onSubmit() {
    //Type appropriate comment here, and begin script below
	var scratchpad = g_scratchpad || NOW;
    if (scratchpad.isFormValid) {
        return true;
    }
    
    var actionName = g_form.getActionName();
    var ga = new GlideAjax("userUtils");
    ga.addParam('sysparm_name', 'isIndia');
    ga.addParam("sysparm_uid", g_form.getValue("requested_for"));
    ga.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == "no") {
            scratchpad.isFormValid = false;
            g_form.addErrorMessage("Invalid Requested for");
        } else {
            scratchpad.isFormValid = true;
			g_form.submit(actionName);
        }
    });
    return false;

}

 

please mark correct and/or helpful.

 

Thanks,

Narsing

 

Robbie
Kilo Patron
Kilo Patron

Hi @Omkarbh97,

 

My advice here would actually be to control this via User Criteria. This means the Catalog Item should not be visible for those user profiles that are not localized in India - why allow someone to fill out a request if they can't submit it.

 

To use 'User Criteria' - see the following link where the example mentions location data as a filtering criterion

 

To help others, please mark correct and/or helpful.

 

Thanks,

Robbie

 

User Criteria with Catalog Items:

https://docs.servicenow.com/bundle/vancouver-servicenow-platform/page/product/service-catalog-manage...

 

If you do however want to allow a user to see and enter the details into a catalog item but prevent them from submitting, see here: https://www.servicenow.com/community/itsm-forum/how-to-restrict-catalog-item-for-user-country/m-p/71...