Can the HTML type of fields be used to contain and display dynamic content while working with service request variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 07:11 AM
We have a requirement wherein we need to display the details of the CIs assigned to a particular user (Requested for) in a tabular form, for which we are using an HTML type of variable, as highlighted below.
Currently, in the above image, we have tried to display some static content, by using the generic HTML <table>, <td>, <tr>, etc. tags.
Could you please advice if this can be done dynamically as well on the basis of the user selected in the Requested For field for the SR, so that if the selected user has 3 devices assigned to him/her in CMDB, those 3 are displayed in the form of a table as above?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 10:55 AM
Yes it can be done dynamically. I have recently created a form that will dynamically add and remove data from that HTML variable. The problem that we have run into is that the HTML variable will truncate the data once the request is submitted. We had a ticket open with ServiceNow who determine that "This custom functionality is not supported". I disagreed with them as the functionality to utilize an onLoad or onChange client script to write data from one place to another is OOB functionality but we did not see eye to eye, thus getting us no support on the problem. We are running the latest patch of Eureka. My workaround solution was to copy the content to a multi-line textbox and use an onChange script for that textbox to re-insert the data back into the HTML variable. That way the data is still maintained even after the request is submitted. Not an elegant solution at all, but it gets the job done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 11:55 PM
Hi Kenneth,
Thanks for the swift update. It is good to hear that you tried making the impossible possible
However, what I am actually looking for is that how can we use the individual cells of the table used in the HTML field to contain dynamic values because if we script anything in between the <td> tags it is displayed as it is.
E.g., if we look at the earlier snapshot that I shared, if I want to display the name of a particular CI into the first cell of the table, the name of the corresponding product into the second cell, how can that be achieved.
Best Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 04:29 AM
Well, the best way that I was able to get this to work started from the foundational construct of the table you've got in the HTML variable. I used SN OOB JQuery to accomplish this functionality. I wrote a script that will sequentially assign an ID attribute to each table row and (in my case) each div. In your case these DIVs would be TD tags which would still work the same. The purpose of this is so that when that HTML variable loads your table, each cell has a unique ID that you can access in the JQuery code. Then from there, you of course need a couple of onChange scripts to accomodate updating the data in the table based on certain conditions on your form. I have pasted my code below as it is used in my instance to update the table rows and cells with unique IDs. Hopefully this helps as a starting point.
// ONLOAD SET THE ID FOR ALL OF THE TABLE ROW TAGS
function setTableRowIDs() {
$j(".main-wrapper").find("tr").each(function(i, el) {
$tableRowClassName = "table_row_";
el.id = $tableRowClassName + (i + 1);
});
// TRIGGER THE FUNCTION TO UPDATE THE DIV IDS
setDivIDs();
}
// ONLOAD SET THE ID FOR ALL OF THE DIVS WITH A CLASS OF INPUT-GROUP
function setDivIDs() {
$divClassName = "row_div_";
$j(".main-wrapper").find("div.input-group").each(function(i, el) {
el.id = $divClassName + (i + 1);
});
// TRIGGER THE FUNCTION TO ADD THE SELECTED ATTRIBUTE TO SELECTED DROP DOWN VALUES
setSelectedAttributes();
}