display message for related list

carlosrlara
Mega Expert

I would like to have a pop-up be displayed to an ITIL user when a Configuration Item Related List is present and active.

I have been reviewing and i can add an info message at the top but this can easily be ignored.

What i have come up with a simple alert message

What i have so far is a client script that i need to set for each table.

Presently, we use Server, Computer, and Network gear. When there is an active related list, i would want to display a message

function onLoad() {

    //Type appropriate comment here, and begin script below

   

  alert('Please Review any open CMDB Task Items');

}

1 ACCEPTED SOLUTION

venkatiyer1
Giga Guru

Hi Carlos,



Sorry my bad. Missed a closing parenthesis.



Should be fine now.



Regards,
Venkat




Code Below:




function onLoad() {


getGrandRows();



}


function getGrandRows() {


setTimeout(function(){


var list = GlideList2.get("x_snc_ci_validator_validation_task");


// You can get the ID of related list from the developer tool bar. Check for the div holding the content and grab the list id.


if(list && list != undefined) {



var numberOfCMDBItems   = list.grandTotalRows; // This parameter tells us number of rows in that list. Which should be greater than zero for alert


}


if(numberOfCMDBItems)


alert("'Please Review any open CMDB Task Items");



}, 3000);



}


View solution in original post

22 REPLIES 22

rafael_merces1
Giga Contributor

Hi Carlos,



Could you please provide a few more details? These releated lists are where? Do you have any prints? You want to validate if the related list is available or an item?



Waiting your comments.



Thanks,


carlosrlara
Mega Expert

The related list is on the configuration item. Presently, the items in use are Computer/Server/Network Gear.



E.g Computer Table



there is a related list for CMDB Validation Task (custom table), which is what i am trying to create the pop-up when there is an active item on the CMDB Validation Task.


Ok, I think I understood your requirenment.



What you can do is add, on your Client Script, and Ajax Call to a function on a Script Include.



EG.:



var cmdb = new GlideAjax('getCMDBTaskItems'); // Here is your script include name


cmdb .addParam('sysparm_name','getCMDB'); // Here is the function name


cmdb .addParam('sysparm_user_id', newValue);


cmdb .getXML(AlertCMDB);




function AlertCMDB(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if (answer) {


  alert('Please Review any open CMDB Task Items');


  }


}



I am not 100% sure that this is completely right, but I think that this is the path. Here you have a wiki article to guide you with Glide Ajax:



GlideAjax - ServiceNow Wiki



Please advise if helpful.



Thanks,


venkatiyer1
Giga Guru

Hi Carlos,



I understand the popup to come up not only if it is a ITIL user but if there are CMDB items. You can have a onload client script   which will have a condition for the logger in user to have itil role. And within that client script you can directly access the related list.



So create a onload client script with condition



g_user.hasRole("itil")   // To check if the user is ITIL


And then the script could do this...



var list = GlideList2.get("ID Of the related list ");


// You can get the ID of related list from the developer tool bar. Check for the div holding the content and grab the list id.


var numberOfCMDBItems   = list.grandTotalRows; // This parameter tells us number of rows in that list. Which should be greater than zero for alert



if (numberOfCMDBItems > 0 ) {



alert("'Please Review any open CMDB Task Items");



} // Instead of alert you can do glide window too.



Thanks


Venkat