Concatenate many-to-many connection in record

Hi All,

Relative new to knack and I am currently creating our product catalogue.

My question is: How do I concatenate the values from two many-to-many connection into one in our product record.

Current situation: We have two lookup tables for the production one called luMaterial and the other luStones.

Each production can have multiple Materials and Stones associated so they can come out like this: Silver, 9kt Yellow Gold and Pearls

I then need to be able to concatenate them together preferably with Text Combo so that I can format it as following:

100% Silver, 9kt Yellow gold, Pearls.


As far as I can see it's not possible to do Text Combo from Many-to-Many connection ( assuming it does not know where to take the value from?)

Would I need to create an intermediate object where I merge them together ? and if so how would that look like?

Any help appreciated.

data refers to the variable 'data' was just declared in the code. data.field_699 refers to that field's value within the variable named 'data.' Field_699 refers to a knack field. Every Knack field has a numerical ID. You can see this in the url as you work in the builder or in the inspector when looking at the web pages.

This is a great reference:

https://www.knack.com/developer-documentation/#working-with-fields

So just curious... with data.field_699_raw for example... I am assuming this is some ID number that refers to the data field, not the title that I am giving it. How is this found to cross reference it?

Thanks, I have worked with Jeremy before. I'm actually trying to rebuild and port my aps from another similar platform to knack... but as there is no concatenate I have to do it differently.

Previously I would just piece together the json on each child record and then combine it together into one value on the parent record, using zapier to push the data.

I have built desktop applications and done a bunch of HTML but not much web based. So I can understand a lot of the code and make changes but its not my comfort zone. Working examples are best lol.

I'll reach out to Jeremy.

@Dan

You can get the data in that format by calling:

var data = Knack.models['view_779'].toJSON();

Replace view_779 with your view.

This will take whatever data is displayed in the view and format it as JSON, and save it as a var: data. You can then make an ajax call to post it somewhere.

You can reach out to Jeremy over at Webmerge. 1 man show it seems, but, the best customer support out there. He responds quickly and is patient with beginners (I know from experience. ) If you have 0 experience with javascript you may need to develop some basic skills before pulling this off on your own. I recommend starting with W3 schools free tutorials. Or hire some help on upwork or codementor and learn as you build. They'll have a head start if they start with this code. I Hope you get what you need. cheers:)

PS.

This is meant to be entered right into the javascript editor in Knack

but you could get similar results with Code by Zapier.

You check out my post on that here:

https://support.knack.com/hc/en-us/community/posts/115002225612-Easy-Cross-domain-API-calls-using-code-by-Zapier-Get-and-Put-one-call-after-another

I need to get the data into this format as a variable to pass to webmerge (json)

[{'Name':'OB Core, Into MH & Breakouts Drill', 'Quantity':'2','Rate':'50.00', 'Total':'100.00', 'SM':'999999'},{'Name':'OB Directional Bore 100mm Froz Cond', 'Quantity':'1','Rate':'50.00', 'Total':'50.00', 'SM':'999999'}]

@justin

Alright that looks pretty much exactly what I am trying to do. I have some programming experience but I have never directly worked with API calls before.

Can I do this with the CODE function in Zapier, or the javascript section of Knact or do I need to do this on some other intermediary?

I understand what I am looking at with most of the lines here but again, not my strong point. Such as where do I get the field numbers etc. You mentioned this was an example by webmerge but I wasn't able to find anything.

Hard to say exactly what this would look like with the info provided but I think you're on the right track. You most likely need another object representing the line Items. If I'm understanding correctly The solution would look something like this:

Each production would be connected One to many to a new child object: line items. (put the connection on the child object) Each of those children would connect to luMaterial and luStones. and include a text combo concat'ing those values.

Make the text combo field the display field on the child object.

Once that's done you can list the connected child values in a table/list that reads: 100% Silver, 9kt Yellow gold, Pearls. etc.

@dan you should be able to push anything via API, you just may need to poll a second view or object and package the data as an array before sending -checkout this example from webmerge. Hope this helps someone :)

//This code grabs data on the parent record from one view and the line items data from another and then sends to webmerge -where they can be used to create a table of the line items

//view 780 has line items -(whatever data you what you want to turn into a list or table)

//view_779 has the parent record data.

$(document).on('knack-scene-render.scene_393', function(event, scene) {
$('#view_782').append('<li><a href="#" id="webmerge" class="kn-button">Send Pro Forma Invoice</a></li>');
// link hander: Print Report
$('#webmerge').click(function(event) {
event.preventDefault();
// get data
var data = Knack.models['view_779'].toJSON();
var models = Knack.models['view_780'].data.models;
var lines = [];
for (var i = 0; i < models.length; i++) {
log(models[i].attributes);
lines.push({
itemid: models[i].attributes.field_641_raw,
vattotal: models[i].attributes.field_695_raw,
vatrate: models[i].attributes.field_694_raw,
brand: models[i].attributes.field_678_raw,
subtotal: models[i].attributes.field_642_raw,
producttype: models[i].attributes.field_677_raw,
quantity: models[i].attributes.field_634_raw,
price: models[i].attributes.field_635_raw,
linetotal: models[i].attributes.field_696_raw,
//fillingtype: models[i].attributes.field_638_raw[0].identifier
});
}
log('data!');
log(models);
log(data);
log(lines);
console.log("data is");
console.log(data);
console.log(lines);
Knack.showSpinner();
$.ajax({
url: 'https://www.webmerge.me/merge/yyyyyy/xxxxxxxxxxxxxxxx',
data: {
lines: lines,
invoicedate: data.field_670_raw,
salesrep: data.field_697_raw,
offerexpires: data.field_672_raw,
notes: data.field_632_raw,
terms: data.field_648_raw,
invoiceNum: data.field_617_raw,
customer_name: data.field_675_raw,
subtotal: data.field_644_raw,
total: data.field_693_raw,
vattotal: data.field_692_raw,
phone: data.field_699_raw,
email: data.field_705_raw,
address: data.field_700_raw,
contactname: data.field_698_raw,
salesemail: data.field_612_raw
},
type: 'POST',
success: function() {
console.log('Invoice Json sent to webmerge');
//alert("success");
Knack.hideSpinner();
},
error: function() {
alert('There was an error creating the invoice');
}
});
});
});

I'm looking for the same answer. With this feature missing it really makes this product lacking as it makes this impossible to push the data out via API to create tables in a merge document. ex: quote, invoice, etc.