Catalog client Script - Abort the submission of item

MR1
Tera Contributor

Hi All,

 

Please validate my script, I am using the catalog client script 'onSubmit' to abort the submission on the service portal. If the reference variable "Resource group" manager is empty. 

The Resource Group is a referring group table(sys_user_group)

function onSubmit() {
	//{

    var business = g_form.getReference('resource_group_to_be_updated', getValue);
//}
	alert('test1');
    function getValue(business) {
       // if(g_form.getValue('resource_group_manager') == '')
		if(business.manager.toString() == '')
        // var user = g_form.getDisplayVaue('resource_group_manager');
        alert('Order Now is disabled if the assignment group manager is empty');
		
        return false;
		}
					}

The user can submit the request. if the reference field is empty then abort the submission. 

 

Thanks

1 ACCEPTED SOLUTION

Hi @MR1 

So the If Statement should be the opposite. If resource_group is A then return true (we don't validate anything)

function onSubmit() {

    if (g_form.getValue('resouce_group') === 'A') {
        return true;
    }

    /*** Pop this gem into your script! */
    if (g_scratchpad.isFormValid) {
        return true;
    }
    var actionName = g_form.getActionName();
    var business = g_form.getReference('resource_group_to_be_updated', getValue);
    return false; //this line was missing

    function getValue(business) {
        if (business.manager.toString() == '') {
            alert('Order Now is disabled if the assignment group manager is empty');
            return false;
        }
		g_scratchpad.isFormValid = true;
		g_form.submit(actionName);
    }
}

 

 

Cheers,

Tai Vu

View solution in original post

11 REPLIES 11

MR1
Tera Contributor

The resource_group_to_be_updated is visible when resource_group is selected as B, C, and D not on A.

 

Thanks

Hi @MR1 

So the If Statement should be the opposite. If resource_group is A then return true (we don't validate anything)

function onSubmit() {

    if (g_form.getValue('resouce_group') === 'A') {
        return true;
    }

    /*** Pop this gem into your script! */
    if (g_scratchpad.isFormValid) {
        return true;
    }
    var actionName = g_form.getActionName();
    var business = g_form.getReference('resource_group_to_be_updated', getValue);
    return false; //this line was missing

    function getValue(business) {
        if (business.manager.toString() == '') {
            alert('Order Now is disabled if the assignment group manager is empty');
            return false;
        }
		g_scratchpad.isFormValid = true;
		g_form.submit(actionName);
    }
}

 

 

Cheers,

Tai Vu