- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 03:51 AM
Hi,
I only want the user to have edit option in pre-populated MRVS in catalog item. Please suggest ways to do it using client script.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 04:09 AM
An onLoad Catalog Client Script like this will work in both the native UI and Service Portal. Ensure the Isolate script box is unchecked. Increase the timeout if the MRVS is slow to load with the form.
function onLoad() {
//MRVS is loaded after the form is loaded. Hence setting a delay of 2 secs.
setTimeout(function() {
disableButtons();
}, 2000);
}
function disableButtons() {
var mrvsid = '444709d9db0f5010a918196c299619ee';//sys_id of MRVS
if(window == null){//Service Portal
//hide Add button on MRVS
this.document.getElementById(mrvsid + '_add_row').style.display = 'none';
//disable Remove All button on MRVS
var mrvs = g_form.getField("rp_mrvs");//internal name of MRVS
mrvs.max_rows_size = 0;
//Hide each X (delete row) icon on MRVS
var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
for(j=0; j<icon.length; j++){
if(icon[j].getAttribute("title") == 'Remove Row'){
icon[j].style.display='None';
}
}
}
else{//native UI method
//hide Add and Remove All buttons on MRVS
document.getElementById('table_variable_buttons_' + mrvsid).style.display = 'none';
//hide only the Add button
//document.getElementById(mrvsid + 'Add').style.display = 'none';
//hide only the Remove All button
//document.getElementById(mrvsid + 'removeAllRows').style.display = 'none';
//hide delete and/or edit icon/button on each row of MRVS
var mrvs = g_form.getValue('multirow'); // Internal name of the MRVS
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
//delete - check Name, may be 'cross' instead
document.getElementsByClassName('btn-sm multi-row-delete-row')[i].style.display = 'none';
//edit
//document.getElementsByClassName('btn icon-edit btn-sm')[i].style.display = 'none';
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 04:09 AM
An onLoad Catalog Client Script like this will work in both the native UI and Service Portal. Ensure the Isolate script box is unchecked. Increase the timeout if the MRVS is slow to load with the form.
function onLoad() {
//MRVS is loaded after the form is loaded. Hence setting a delay of 2 secs.
setTimeout(function() {
disableButtons();
}, 2000);
}
function disableButtons() {
var mrvsid = '444709d9db0f5010a918196c299619ee';//sys_id of MRVS
if(window == null){//Service Portal
//hide Add button on MRVS
this.document.getElementById(mrvsid + '_add_row').style.display = 'none';
//disable Remove All button on MRVS
var mrvs = g_form.getField("rp_mrvs");//internal name of MRVS
mrvs.max_rows_size = 0;
//Hide each X (delete row) icon on MRVS
var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
for(j=0; j<icon.length; j++){
if(icon[j].getAttribute("title") == 'Remove Row'){
icon[j].style.display='None';
}
}
}
else{//native UI method
//hide Add and Remove All buttons on MRVS
document.getElementById('table_variable_buttons_' + mrvsid).style.display = 'none';
//hide only the Add button
//document.getElementById(mrvsid + 'Add').style.display = 'none';
//hide only the Remove All button
//document.getElementById(mrvsid + 'removeAllRows').style.display = 'none';
//hide delete and/or edit icon/button on each row of MRVS
var mrvs = g_form.getValue('multirow'); // Internal name of the MRVS
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
//delete - check Name, may be 'cross' instead
document.getElementsByClassName('btn-sm multi-row-delete-row')[i].style.display = 'none';
//edit
//document.getElementsByClassName('btn icon-edit btn-sm')[i].style.display = 'none';
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 05:03 AM
the only way is DOM which is not recommended.
refer below link
Disable buttons in MultiRow Variable Set
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader