Restrict the duplicate entry on the multi row variable set

Community Alums
Not applicable

Hi All, 

 

Having a requirement that, we are having a form through that we are inserting records into hardware table. 

On the form we are having a multirow variable set through that we are inserting the serial numbers based on that serial number records are inserted in the table. 

 

while adding the serial numbers in the multi row variable set, we need to validate the entered serial number whether there is an asset record in the hardware table with the same serial number. if yes then need to restrict the form submition if no then able to submit the request. 

 

Any suggestion on the above requirement to achieve. 

 

 

8 REPLIES 8

Oh, so you're using Service Portal.  Since this is onChange getXML will work the same, and does still work in SP.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	var ga = new GlideAjax('MRVSvalidation');
	ga.addParam('sysparm_name', 'snExists');
	ga.addParam('sysparm_sn', newValue);
	gr.getXML(getResponse);
	
	function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer"); 
	    if (answer == 'yes') {
    	    g_form.clearValue('serial_number_1');
		    g_form.addErrorMessage('Serial Number already exists.');
	    } else {
		    g_form.clearMessages();
	    }
    }
}

Community Alums
Not applicable

Hi @Brad Bowman  

 

Thanks for suggestion, but its still not restricting to abort the duplicate value entry. 

chanti1_0-1695448956681.png

Able to show error message as the record is already exists, but allowing the duplicate entry. 

Any suggestions. 

 

 

If serial_number_1 is the name of the variable, it sounds like there are no other mandatory variables in the MRVS and/or you are typing a serial number then clicking the Add button, so the add row action is completing before the script gets to the server and back.  This is a challenge with the asynchronous nature of Service Portal.  Here's one workaround that seemed to work in my mock-up of this use case.   

 

Just add an alert before the GlideAjax call in the Client Script - something like 'Validating Serial Number...'.  That seemed to allow the script to finish and abort the Add action in my testing.  If that doesn't work in your environment for some reason I have a bit more convoluted workaround.

Community Alums
Not applicable

Hi @Brad Bowman  

chanti1_0-1695491799209.png

chanti1_1-1695491981410.png

 

i think it's working, after alert its aborting the insert of the duplicate record. 

Thank you @Brad Bowman .