I want to create a monthly event for items due to expire within the next 6 months, firslty how would I just display items where the expiry date is in the next 6 months and then how would I add all those items shortcodes into a remarks field? May be missing something obvious here but data only shows when I add the [0] at the end of the variable.
Thanks
Page 1 / 1
Variable assyst searches always evaluate to an array. [0] gets the 1st element of that array. To combine all of the element’s shortcode’s you could use JavaScripts map() & join() functions:
"Items due to expire:\n" + variables.expringItems.map(function(i){return i.shortCode}).join('\n')
Which produces output like:
Items due to expire: CP01369 CP01441
I think a mapper like this meets your needs:
You could also consider having second mapper which linked the expiring items to the event, rather than storing that as text.
I would like to take the opportunity to add to @Paul McCulloch’s solution.
By creating an array of items in a variable Assyst search field, you can for instance use this array to construct a table for adding to the event’s rich remark.
As an example here is how you can construct the table with hyperlinks to the item
// Construct the table fron previous datamapping // Uses a 'variable Assyst Search' field as input that should return an array of items from the CMDB // Assumes elements in array at minimum have both id, and shortCode
var items = variables.expiringItemsArray || []; // Set to empty array to avoid undefined behaviour if missing 'items' array var baseUrl = "https://assyst-OUR-DOMAIN.net/assystweb/application.do#item%2FManageItem.do?dispatch=manageParent&currentTab=searchForm&id=";
var table = "<table><tr><th>Short Code</th><th>Expiry Date</th></tr>";
if (items.length > 0) { for (var i = 0; i < items.length; i++) { var item = items[i]; var shortCodeLink = '<a href="' + baseUrl + item.id + '" target="_blank">' + item.shortCode + '</a>';
table += "<tr>"; table += "<td>" + shortCodeLink + "</td>"; table += "<td>" + (item.expiryDate || "") + "</td>"; //Empty string catch for resuabilty in cases where expiryDate is customized as Hidden table += "</tr>"; } } else { table += "<tr><td colspan='2'>No expiring items found</td></tr>"; }
table += "</table>";
// Output 'table' for use in the rich remarks field table;
This table can then be put into a rich remarks field alongside any other text you want to add.
ItemTable = variables.ItemTable || "" //Protect against undefined if the variable field 'ItemTable' is missing
"<p>The following items will expire in 6 months: <p>" + ItemTable
Also, a heads-up: depending on the ETM/IPaaS version you’re on, you might not have date ranges available in ETM. ETM 1.10 adds support for date ranges, but if you’re on 1.9 or earlier, using a variable Assyst search field on its own will probably not work, as it only accepts a single date in an expiryDate and such a query will return items with expiry after the given date… As a workaround, you could try using common.search to do the date range lookup of items. However, I’ve not personally been able to get the syntax for date range in an common.search correct during this testing.
Lastly a small note about Paul’s idea of linking items to the event: This is probably the preferred way for reporting and my personal favorite as it allows for later reuse of data with use of VTL in action templates, etc. However, creating such a channel is a bit more involved, as it will likely involve three datamappers: the aforementioned event mapper, a Linked Item Group mapper, and lastly a Linked Item mapper that gets the newly created Linked Item Group and iterates on the item array from the first mapper. While not difficult in and of itself, it does add several more layers of complexity.
This is a good use for Velocity, rather than JS, in mapper expressions. Rather than lots of string concatenation we can do something like: