Making a Downloadable Attachment in an Order Guide

jmiskey
Kilo Sage

Hello.  We currently have many similar Catalog Items that use shared Variable Sets.  Many of these Catalog Items have files that the user needs to download, fill-out, and re-attach to the Catalog Item. 

 

We do this by attaching the required files to be downloaded to each of the Catalog Items (different Catalog Items have different forms to download).  We then use a "Custom with Label" variable in one of the shared Variable Sets to create the file download link in the Catalog Item.  We have created a Custom Widget, which looks like this:

jmiskey_0-1784214702279.png

 

jmiskey_2-1784214750423.png

 

This works perfectly in standalone Catalog Items (we have been using it for years).  However, if we move these Catalog Items into an Order Guide, it no longer works.  My "Download Link" does not display, so they cannot click or download anything.

 

Here is how it looks (from ESC) in a standalone Catalog Item:

jmiskey_3-1784215089176.png

 

And here is how it looks when that same Catalog Item is in an Order Guide:

jmiskey_4-1784215156739.png

 

You can see the link is missing.  I need to figure out how to make this work in an Order Guide, and I need the solution to be dynamic (not hard-code in the attachment id), as the Variable is found in a Variable Set shared by many of these Catalog Items (the file to download is attached directly to the Catalog Item).

 

Does anyone have any good solution to this, whether it is updating what I currently have, or trying an entirely different method?

 

Thanks

 

9 REPLIES 9

@jmiskey 

Thank you for marking my response as helpful.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Tanushree Maiti
Tera Patron

Hi @jmiskey 

 

Link will be displayed when you will define the on click ( here ng-click) properly.

 

Sample :

TanushreeMaiti_0-1784222585083.png

 

Then define it in Client Controller.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

You will have to forgive me - I have never created any widgets myself, so am not certain on how to do that (this widget was created by someone who left our company long ago).

 

Here is the current code in the "Body HTML template" section of our widget"

<div>
  <ul>
  
    <li ng-repeat="url in data.urls">
        <a ng-href={{url}} target='_blank' >Download link</a>
    </li>
  
  </ul>

<!-- your widget template -->
</div>

and here is what is currently in the "Client controller" section:

function() {
  /* widget controller */
  var c = this;
}

 

 

jmiskey
Kilo Sage

So, we really couldn't figure out a good way to fix the automation of this, mostly because of my inexperience with Custom Widgets.  We dug a little deeper, and determined we only need to update 10 Catalog Items, so we ended just hard-coded those ones, and getting rid of our Variable Sets. 

 

It would have been nice to figure out a dynamic way to do it, but it probably isn't worth the effort.

You can get the item id from the options object in the cat_item prop.

<div>
	<ul ng-if="c.data.attachments.length">
  	<li ng-repeat="attachment in c.data.attachments"><a href="/sys_attachment.do?sys_id={{attachment.sysId}}">{{attachment.name}}</a></li>	
  </ul>
</div>
(function () {
	data.attachments = (function (guideItemId) {
		var attachmentGr = new GlideRecordSecure("sys_attachment"),
			attachmentIds = [];
		attachmentGr.addQuery("table_sys_id", guideItemId);
		attachmentGr.query();
		while (attachmentGr.next()) {
			attachmentIds.push({
				sysId: attachmentGr.getUniqueValue(),
				name: attachmentGr.getValue("file_name")
			});
		}
		return attachmentIds;
	})(options.cat_item);
})();