Check Mandatory Values in Template Value type of field on form

U_verma
Tera Expert

HI All,

 

For one of my requirements, I have to check while updating a form if the template value contains fields like
Short Description and assignment group  with values, currently I am using below script with split twice, but somwhere I feel like we have better way to configure this also this script is not validating in case one field is missing. Looking forward to the comments on this. Thanks 

 

Using Business rule 

var templateValue =current.u_template_values;
//Check if it has short_description and assignemnet group then abort action
if(templateValue.indexOf("short_description") ==-1 && templateValue.indexOf("assignment_group") ==-1 ){
current.setAbortAction(true); 
}
else{
var split = templateValue.split('^'); //if we have those 2 values then check if it contains any value
for(var i = 0; i < split.length; i++) {
if(split[i].startsWith('short_description') || split[i].startsWith('assignment_group')){
var checkagain =split[i].split('=');
if(!checkagain[1]){
current.setAbortAction(true);
gs.addErrorMessage('please check condition');
}
}} }
1 ACCEPTED SOLUTION

U_verma
Tera Expert

HI Tushar,

 

Thanks for the code but this only works to check if it has short description and assignment group and not if it is blank,
However I was able to tweak the regex bit and now it is working as expected.

 

var templateValue = current.u_template_values;
if (/^short_description=[^|^]+?\^assignment_group=[^|^]+?\^/.test(templateValue)) {
 current.setAbortAction(true);
gs.addErrorMessage('Please include both "short_description" and "assignment_group" in the template with values.');
}
 
Thank you so much for your Help!!!

View solution in original post

3 REPLIES 3

Tushar
Kilo Sage
Kilo Sage

Hi there,

 

var templateValue = current.u_template_values;

// Check if it has short_description and assignment_group then abort action
if (!/short_description=[^|^$]*\^|assignment_group=[^|^$]*\^/.test(templateValue)) {
    current.setAbortAction(true);
    gs.addErrorMessage('Please include both "short_description" and "assignment_group" in the template with values.');
}

 

Please mark this response as correct and/or helpful if it assisted you with your question.

Regards,
Tushar

U_verma
Tera Expert

HI Tushar,

 

Thanks for the code but this only works to check if it has short description and assignment group and not if it is blank,
However I was able to tweak the regex bit and now it is working as expected.

 

var templateValue = current.u_template_values;
if (/^short_description=[^|^]+?\^assignment_group=[^|^]+?\^/.test(templateValue)) {
 current.setAbortAction(true);
gs.addErrorMessage('Please include both "short_description" and "assignment_group" in the template with values.');
}
 
Thank you so much for your Help!!!

Tushar
Kilo Sage
Kilo Sage

Hi there,

 

I thought so,i was missing something here and thanks for sharing the final solution.

 

Great work.