- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 08:10 AM
So I have a tricky Catalog Item/Workflow I am working on. I need to create and pre-populate a Multi-Row Variable Set (MRVS) from a data table we have in ServiceNow. Our ultimate goal is to have this display only on the Catalog Task that the Workflow creates once the Catalog Item is submitted, and to allow the Task assigners to fill it out, and we would like to take away the Add/Remove options from the MRVS, so all that they can do is edit the existing pre-populated records. But we are taking this bit-by-bit.
I have run into a problem with how the MRVS is being displayed in the Task. I have temporarily disabled my Catalog UI Policies which hide it from the Catalog Item on the Service Portal and from the RITM that gets created, to see if that helps. So right now, it shows in all three places.
Here is what it looks like on the Service Portal:
Here is what it looks like on the RITM:
And here is what it looks like on the Task:
As you can see, for some reason, the "Actions" title is being removed from the Header row on the Task, so all the Titles are shifted over one, and do not line up with the actual data.
Does anyone have any idea on what might be causing this behavior, or do you have any idea on how to correct it?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 11:36 AM
OK, so it turns out that there was an general Client Script that we had that was affecting this.
So we had to amend the Client Script which is running against the onLoad event of the Catalog Task table like this (this is just a portion of a much larger script in there that accounts for various exceptions):
//Make variables editable if Task is active for this Catalog Item, otherwise lock
else if(((g_form.getValue('request_item.cat_item') == "720f2816db91d010bc827afc0f9619b3"))){
if(g_form.getValue('active') == "true"){
g_form.setVariablesReadOnly(false);
}else{
g_form.setVariablesReadOnly(true);
}
}
Then we moved the script to hide the Add/Remove options on the MRVS out of our Catalog Client Script (that is used to pre-populate the MRVS), to a basic Client Script that runs onLoad of Catalog Task, with this code:
function onLoad() {
//Get values
var catItem = g_form.getValue('request_item.cat_item');
//Run on Security Termination Form
if (catItem == '720f2816db91d010bc827afc0f9619b3' && g_user.hasRole('Security Catalog')){
setTimeout(function () {
//hide the add/remove table
var z = this.document.getElementsByClassName("sc-table-variable-buttons");
// alert(z.length);
var k;
for (k = 0; k < z.length; k++) {
z[k].style.display = 'none';
}
//remove "x" (delete) from individual records
var y = this.document.getElementsByClassName("btn btn-sm icon-cross multi-row-delete-row");
// alert(y.length);
var j;
for (j = 0; j < y.length; j++) {
y[j].style.display = 'none';
}
}, 1000);
}
}
Once we did all this, the headers appeared as they should. (Note: We chose to do the above script in a Client Script, so we can re-use it easily if we have other MRVS that we want to set up in the same manner).
So we have the MRVS only being displayed on the Catalog Task (not on Catalog Item or Requested Item). We use a Catalog UI Policy to hide it in theose places. The Catalog Client Script that pre-populates the MVRS only runs against the Catalog Item. That prevents it from re-running and overwriting all changes made to it when it is opened up in the Task.
The variables are editable only while the Task is active. Once it is closed, everything is locked down, which is exactly the way we need it to work.
So, finally, eveything working just the way we needed!
Thanks to all who chimed in and helped steer me in the proper direction.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 08:11 AM
Is there a Catalog Client Script, UI Policy, or Client Script on sc_task that are making variables read only?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 08:27 AM
I have a Catalog UI Policy on the MRVS to make the Application field read-only, and I have a Catalog Client Script on the Catalog Item, which tries to hide the Add/Delete buttons on the MRVS (this part is a work in progress, and works better in some parts better than others).
The odd thing is I set this up much like I did with a Test example (that also has the same type of Catalog UI Pollicy and Catalog Client Script on it), and it works correctly on that (in that it does show the "Actions" title in the Header of the MRVS).
I am not sure if I understand how making a variable read-only would have any effect on the Actions title showing up in the Header bar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 08:42 AM
Hi,
I am able to view the Add/Remove ALL on catalog task form
Did you use some script to hide those?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 08:53 AM
Yes, I cobbled some script together that I found in some old Community Posts. The script is not consistent where it works, as you can see from my images. That is still a work in progress, but that is not as important right now as getting the titles to appear properly.
This is what the Catalog Client Script looks like that is supposed to be hiding the Add/Remove actions:
function onLoad() {
//Populate MRVS with data from table and disable all Add/Delete buttons from MRVS
var tlist = [];
//call script include to get array
var ga = new GlideAjax("ListApps");
ga.addParam("sysparm_name","getApps");
ga.getXMLAnswer(returnApps);
function returnApps(response){
var answer = response;
tlist=answer.split(",");
var obj = [];
for (var i = 0; i < tlist.length; i++){
obj.push({
"actions": "",
"application": tlist[i],
"has_account": "",
"user_id": ""
});
}
g_form.setValue("security_applications", JSON.stringify(obj));//replace varset with table variable
}
// Function to hide Add/Remove buttons
setTimeout(function () {
// hide remove button
var x = this.document.getElementsByClassName("btn btn-default");
//alert(x[4].getAttribute("ng-click"));
var i;
for (i = 0; i < x.length; i++) {
if (x[i].getAttribute("ng-click") == 'c.clearValue()' && x[i].getAttribute("type") == 'button'){
x[i].style.display = 'none';
}
}
// hide all x buttons
var y = this.document.getElementsByClassName("wrapper-xs fa fa-close");
var j;
for (j = 0; j < y.length; j++) {
y[j].style.display = 'none';
}
//***PROBLEM AREA
//hide add button
var z = this.document.getElementsByClassName("btn btn-primary m-r");
//alert(z.length);
var k;
for (k = 0; k < z.length; k++) {
if (z[k].getAttribute("title") == 'You can add only 5,000 rows'){
z[k].style.display = 'none';
}
}
}, 1000);
}