Check Multiple Conditions before Insert/Update

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Check Multiple Conditions before Insert/Update

Post by angus » 2022-05-23 15:21

Hi everyone, I need some help.

I have an error function in the -dv.js file. I want to show an error if the following is true:
qgate = A1
solutions = 5,6,7,8,10,13,14
reasons <> 'TBC.20' OR 'TBC_10'

The issue I have with the code below is that it shows an error all the time. I change the qgate to 'A1', soloutions to 8 and reasons to TBC.20 but it still comes back with an error too.

can anyone help me with this?

Code: Select all

function show_error(field, msg){
				modal_window({
					message: '<div class="alert alert-danger">' + msg + '</div>',
					title: 'Error in ' + field,
					close: function(){
						$j('#' + field).focus();
						$j('#' + field).parents('.form-group').addClass('has-error');
					}
				});
				
				return false;
			}

$j(function(){
	$j('#update, #insert').click(function(){
		/* Make sure if Qualitygate is A1 we only allow certain reasons */
		var qgate = $j('#qgate').val();
		var reasons = $j('#reasons').val();
		var solutions = $j('#solutions').val();
		
		console.log(qgate, reasons, solutions);
		
		if((qgate = 'A1') && (solutions == 5 || solutions == 6 || solutions == 7 || solutions == 8 || solutions == 10 || solutions == 13 || solutions == 14 )
			&& (reasons != 'TBC.20' || reasons != 'TBC_10'))
		{
			return show_error('reasons', 'this is a test');
		}
	});
})
AppGini 22.13

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Check Multiple Conditions before Insert/Update

Post by pbottcher » 2022-05-29 20:57

Hi,

I guess you have a syntax error in the qgate check.

try

Code: Select all

if((qgate == 'A1')
instead of

Code: Select all

if((qgate = 'A1')
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Check Multiple Conditions before Insert/Update

Post by angus » 2022-06-07 11:42

Perfect it works
AppGini 22.13

Post Reply