various shenanigans.

Nintex Form: Get Attachment Link(s) from Secondary List

Use Case: Hiring Application form that needed to pull Resume attachment from Candidates list.

I first setup a calculated column that retrieves the ID from a Candidate Lookup List column. I set a Javascript variable to ‘cID’.
parseLookup(Candidate, False)
I then created a hidden Single Line Text box with a Javascript variable set to ‘rlink’
I added a Calculated Column that uses that ‘rlink’ field as it’s default value.

In the form’s custom Javascript settings, I have the following code:

(function getAttachments() {

	  var itemId = NWF$("#" + cID).val();
	  			console.log(itemId);
    var listName = "Candidates";   
    var url = _spPageContextInfo.webAbsoluteUrl;
    var requestUri = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles";
		  			console.log(requestUri);
    var str = "";
    $.ajax({
        url: requestUri,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        async: false,
        success: function (data) {
		 for (var i = 0; i < data.d.results.length; i++) {
                str += <a target='_blank' href='" + data.d.results[i].ServerRelativeUrl + "' rel="noopener">" + data.d.results[i].FileName + "</a>;
                if (i != data.d.results.length - 1) {
                    str += "
"; } } }, error: function (err) { } }); NWF$("#" + rlink).val(str); console.log(str); })();

When a user views the application form, a link directly to any attachments will display.

Close Bitnami banner
Bitnami