How can we disable the pencil icon in Multi Row Variable Set for certain record?

Aarushi2
Mega Contributor

my Requirement is to disable the pencil icon i.e Edit icon in a multi-row variable set for a certain record?

Any solution would be welcome.

Thanks in advance

find_real_file.png

1 ACCEPTED SOLUTION

Hello Arushi,

Good to know that my articled helped you. If you want to hide for specific icon, there is no directly way.

In your rows , you can do a check for the text in the 1st column (after pencil) and if that matches you can hide it. Here is sample code for that.

    icon = this.document.getElementsByClassName("wrapper-xs fa fa-pencil");
    for (i = 0; i < icon.length; i++) {
        if (icon[i].getAttribute("title") == 'Edit Row') {
            if (icon[i].parentNode.nextElementSibling.innerText == 'YOUR TEXT') {
                icon[i].style.display = 'None';
            }
        }
    }

In the code, replace it with your text and then check. Then it will disable the pencil icon only for that row having that text.

Mark the comment as a correct answer and helpful once worked.

 

View solution in original post

13 REPLIES 13

Hi

yes, I want that if I have 5 rows then I want to remove it for a particular row like for 2nd row the edit icon should be disabled not for all rows.

 

Hi,

will it be always for 2nd row?

what happens if there is only 1 row

for your example if you have 5 rows and want to hide it only for 2nd row then use this script

  1. Ensure Isolate Script field is set to false
  2. This field is not on form but from list you can make it to false

If you want to hide it on RITM then use Applies on Requested Item -  True

If you want to hide it on SC Task then use Applies on Catalog Task  - True

function onLoad() {
    //Type appropriate comment here, and begin script below

   var z = this.document.getElementsByClassName("btn icon-edit btn-sm");
   // index starts from 0
   // so z[1] means 2nd row
   z[1].style.display = 'none';

}

find_real_file.png

Regards
Ankur

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

Hi sir,

The row can b different it can b two or more rows also.

I'm getting an error when I run code as There is a JavaScript error in your browser console why it's coming so? 

 
Thanks

Hello Arushi,

Good to know that my articled helped you. If you want to hide for specific icon, there is no directly way.

In your rows , you can do a check for the text in the 1st column (after pencil) and if that matches you can hide it. Here is sample code for that.

    icon = this.document.getElementsByClassName("wrapper-xs fa fa-pencil");
    for (i = 0; i < icon.length; i++) {
        if (icon[i].getAttribute("title") == 'Edit Row') {
            if (icon[i].parentNode.nextElementSibling.innerText == 'YOUR TEXT') {
                icon[i].style.display = 'None';
            }
        }
    }

In the code, replace it with your text and then check. Then it will disable the pencil icon only for that row having that text.

Mark the comment as a correct answer and helpful once worked.

 

If the value to check is not in the 1st but in 2nd column after pencil, then you can check like this. Same logic whichever column it is. 

use nextelementSibling to go to that element and use innerText to get the value.

icon = this.document.getElementsByClassName("wrapper-xs fa fa-pencil");
    for (i = 0; i < icon.length; i++) {
        if (icon[i].getAttribute("title") == 'Edit Row') {
             //this gives you 1st element
	     var elm = icon[i].parentNode.nextElementSibling; 		
             //below nextElementSibling again to elmwill you 2nd column text after edit icon. 
            if (elm.nextElementSibling.innerText == 'Field one 1') {
                icon[i].style.display = 'None';
            }
        }
    }