The Zurich release has arrived! Interested in new features and functionalities? Click here for more

MultiRowVariableSet date Validation

Hari Krishna1
Tera Contributor

Hi Experts,

My requirement is in "Multi row variable set, the  second record of the 'start date' it should not the less than of 'end date' of the first record, I written On_change Catalog client scripts in MRTS but it not working as expected ,please any one can suggest or give inputs ,how can i achieve this ,

 

for reference see the attachment :

in below image the first record End date is 2024-08-01 , but in second record the Start date should not select the less than of @2024-08-01 date .

Capture.PNG

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If the use case is truly limited to 2 rows in the MRVS, this script onChange of the Start Date MRVS variable will work:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    var mrvs = g_service_catalog.parent.getValue('mrvs1'); //replace with your mrvs internal name
    
	if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a parsing error
		var obj = JSON.parse(mrvs);

        //prevent end date less than start date of first row
        if (newValue < obj[0].end_date_mrvs) { //replace with your MRVS variable name
            alert('Start Date cannot be early than previous row End Date.');
            g_form.clearValue('start_date_mrvs'); //replace with your MRVS variable name
        }
	}
}

 

If there's a possibility that more rows will be added, and the requirement is that the new row start date should never be before the previous row end date, it would look more like this:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    var mrvs = g_service_catalog.parent.getValue('mrvs1'); //replace with your mrvs internal name
    
	if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a parsing error
		var obj = JSON.parse(mrvs);
		//prevent end date less than start date of previous record
        if (newValue < obj[obj.length-1].end_date_mrvs) { //replace with your MRVS variable name
            alert('Start Date cannot be early than previous row End Date.');
            g_form.clearValue('start_date_mrvs'); //replace with your MRVS variable name
        }
	}
}

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

If the use case is truly limited to 2 rows in the MRVS, this script onChange of the Start Date MRVS variable will work:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    var mrvs = g_service_catalog.parent.getValue('mrvs1'); //replace with your mrvs internal name
    
	if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a parsing error
		var obj = JSON.parse(mrvs);

        //prevent end date less than start date of first row
        if (newValue < obj[0].end_date_mrvs) { //replace with your MRVS variable name
            alert('Start Date cannot be early than previous row End Date.');
            g_form.clearValue('start_date_mrvs'); //replace with your MRVS variable name
        }
	}
}

 

If there's a possibility that more rows will be added, and the requirement is that the new row start date should never be before the previous row end date, it would look more like this:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    var mrvs = g_service_catalog.parent.getValue('mrvs1'); //replace with your mrvs internal name
    
	if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a parsing error
		var obj = JSON.parse(mrvs);
		//prevent end date less than start date of previous record
        if (newValue < obj[obj.length-1].end_date_mrvs) { //replace with your MRVS variable name
            alert('Start Date cannot be early than previous row End Date.');
            g_form.clearValue('start_date_mrvs'); //replace with your MRVS variable name
        }
	}
}

 

Thanks Brad Bowman, its fixed my issue.