Special Mandatory Requirements for Multi-Row Variable Set (MRVS)

jmiskey
Kilo Sage

We have a Termination Request Catalog Item on our Service Portal.  Basically, the manager selects the user and the term date, and submits the request.  Then, a Task is created for our Security team to verify and delete all the user's accounts.

The list of Security Applications is constantly changeing, and we do not want to have to edit the Catalog Item every time one changes.  To get around that, what we did is create a custom table that lists all the Security Applications, and an Active flag to show if those Applications are currently active or not.  Then, on the Catalog Item, we have a Multi-Row Variable Set (MRVS) that is pre-populated with the list of Active Security Applications.  This MRVS is hidden from the Catalog Item and the RITM, and only is displayed on the Task for Security.  We have removed the Add/Remove capabiities from the MRVS, so all they can do on the Task is edit the records lthat have been pre-populated.

Our MRVS shows three fields:

- Application Name: this is pre-populated and made read-only, so they cannot change it on the Task

- Has Account?: this is a multiple choice field, with options "Yes" and "No"

- User ID: this is a text field that becomes required if they mark "Yes" for "Has Account"?

So an excerpt from this MRVS looks like this:

find_real_file.png

In actuality, there are about 30 Applications listed.  Everything is working great, but there is one more thing we want/need to do.  For every Application listed, we want to require them to put a "Yes" or "No" in the "Has Account?" field (this indicates to our auditors that they have checked every single Application).  We made the field a required field, but that only takes affect if they actually choose to edit that record.  If they do not edit every record listed, then they can Close the task without filling out that field for every record.

So the question is, how can we ensure that they have edited every record, and every records has a "Yes" or "No" in the "Has Account?" field before Closing the task?

Thanks.

 

 

14 REPLIES 14

Ash10Patil
Kilo Guru

Hi,

OnSubmit client script can be used to check mandatory values.

You can access MRVS value using g_form.getValue(<mrvs varibale name>), it gives value in JSON format.

You can apply loop on json data and check for "Has Account"(or any other variable) value, and prevent form submission if mandatory values not present.

 

Thanks.

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

Unfortunately you cannot use onChange client script on MRVS variable.

You need to use onSubmit client script

1) get the value of MRVS as json

2) parse the json and check whether "Has Account?" has value or not

3) if not then show alert and stop form submission

Sample Script:

Note: give your mrvs variable name and has_account variable name

function onSubmit(){

var value = g_form.getValue('mrvs_variable');

var parser = JSON.parse();

var isPresent = true;

for(var i=0;i<parser.length;i++){

if(parser[i].has_account == ''){
isPresent = false;
break;
}

}

if(isPresent.toString() == 'false'){
alert('Please give has account for pending row');
return false;
}

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the replies.  Unfortunately, I have been unable to get it to work.

Note that my Variable Set is "security_applications", and has the following 3 fields:

- application (display field)

- has_account

- user_id

And I only want/need this rule to be applied on when the Catalog Task is updated. 

 

First, I tried to apply it to a Catalog Client Script at the Catalog level like this:

find_real_file.png

And I got an error message when I tried to close the Task that said:

Submit canceled due to a script error - please contact your System Administrator

When I inspected the Console, it told me:

Failed to load resource: the server responded with a status of 404 (Not Found)

 

So then I tried moving the Client Script directly to the Variable Set, like this:

find_real_file.png

(with the same script)

Then when I tried it, it did not error, but it allowed me to Close the Task without updating all the records.

So I was looking at the script a little closer, and noticed that you are setting a variable called "value", but then it doesn't appear that the variable is being used anywhere in the script.  So I tried changing the JSON.parse line to:

var parser = JSON.parse(value)

but that did not seem to make any difference (I admit that I have really not used JSON that much, so I am not that familiar with it).

Do you know why that Client Script does not appear to be working?

 

 

 

@Ankur Bawiskar 

Do you have any idea what I may be doing wrong in trying to incorporate your solution, as per my previous post?