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

Hi,

you can use getValue() on MRVS

try adding some alert to confirm

If you are getting the json string you should be able to parse it

function onSubmit(){

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

alert('JSON is ' + value);

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;
}

}

Regards
Ankur

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

OK, I tried that, and I can see that it is erroring.

When I close the Task, I first get the alert that shows the values.  It starts like this:

find_real_file.png

However, then I get an error, and no more alerts (it appears that it doesn't get to the last alert you added near the end).

Here is the error message I get:

Error MessageonSubmit script error: SyntaxError: Unexpected token u in JSON at position 0

I am not really sure what is telling me.  Any idea?

Hi,

ok the json looks like that

But that json string doesn't contain has_account variable information

Regards
Ankur

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

Actually, I think it does.  The sys_id of the "has_id" variable is "773d2ddedb59d010bc827afc0f961963", and that sys_id is showing up in the section of the alert that I posted.

Interestingly, if in addition to the "Applies on Catalog Tasks" checkbox, I also check the "Applies on Catalog Item view" box, it will show the alert on the original submission of the form in the Service Portal, and it that alert box, it actually shows the variable names instead of the variable's sys ids.

It looks like this:

JSON is [{"actions":"","application":"Active Directory ID","has_account":"","user_id":""},{"actions":"","application":"Personal Drives","has_account":"","user_id":""},{"actions":"","application":"Privileged Account ID","has_account":"","user_id":""},{"actions":"","application":"Treasury","has_account":"","user_id":""},

Not sure why it shows the friendly names on on the Catalog Item View, and sys_ids on the Catalog Task.

I was just wondering, this method that we are trying, have you ever done something like this and gotten it to work before?  Or are you just trying to figure it out for the first time, like me.

 

Hi,

You are missing a line of code here.

Please try this:

function onSubmit(){

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

alert('JSON is ' + value);

var parser = JSON.parse(g_form.getValue('security_applications'));
var length = parser.length;
JSON.stringify(parser);

var isPresent = true;

for (var i = 0; i < length; i++) {
if (parser[i].has_account == '') {
isPresent = false;
break;
}
}
if (isPresent.toString() == 'false') {
alert("Please specify account");
return false;
}
}

 

Let me know if this is helpful!