Welcome to the community, @Nareg_Kara-Yacoubian! :grinning_face_with_big_eyes:
You’re not missing anything. The way I read that, the update to add a link to the original record was never added. What was added was an update to copy over all linked record fields.
If you want to add a link to the original, change this line:
let obj = {}
to this:
let obj = {"Link to Original": n{id: original.id}]}
Replace "Link to Original"
with the name of the field that will contain the link to the original record.
Hi Justin,
Thanks for the quick response!
What was added was an update to copy over all linked record fields.
Strange, as even without the second addition, i.e. the original code, it copies over linked records no problem in the duplicate. In any case that part works so I’m not going to touch it further.
Replace “Link to Original” with the name of the field that will contain the link to the original record.
Hm, I tried this but it didn’t work. Here is the exact code I’m using:
let table = base.getTable("Sample")
let query = await table.selectRecordsAsync({fields: table.fields})
let records = query.records
let fields = table.fields
let exclude = e"Trans 10"]
let filteredFields = fields.filter(x => !exclude.includes(x.name) && x.isComputed == false)
let original = await input.recordAsync("Original Record", table)
let obj = {"Parent": "{id: original.id}]}
filteredFields.map(x => {
let fieldValue = original.getCellValue(x.name)
let method = fieldValue && x.type=="multipleRecordLinks" ? fieldValue.map(y => ({id: y.id})) : fieldValue
Object.assign(obj, {ix.name]: method})
})
await table.createRecordAsync(obj)
In this structure, “Sample” is the table name, “Trans 10” is the excluded field, and “Parent” is the name of the field that needs to contain the link to the original record. Parent is a linked field type, and will sometimes contain a value (which needs to be replaced) or will sometimes be blank (in which the most recent parent needs to be filled). We will use this data down the line to construct trees, in which all children can be linked down to child samples.
Fairly soon we’re going to get some dedicated Javascript assistance, but I would really like to get this one thing working to dramatically simplify our workflow in the interim.
Thanks!
Nareg
Hi Justin,
Thanks for the quick response!
What was added was an update to copy over all linked record fields.
Strange, as even without the second addition, i.e. the original code, it copies over linked records no problem in the duplicate. In any case that part works so I’m not going to touch it further.
Replace “Link to Original” with the name of the field that will contain the link to the original record.
Hm, I tried this but it didn’t work. Here is the exact code I’m using:
let table = base.getTable("Sample")
let query = await table.selectRecordsAsync({fields: table.fields})
let records = query.records
let fields = table.fields
let exclude = e"Trans 10"]
let filteredFields = fields.filter(x => !exclude.includes(x.name) && x.isComputed == false)
let original = await input.recordAsync("Original Record", table)
let obj = {"Parent": "{id: original.id}]}
filteredFields.map(x => {
let fieldValue = original.getCellValue(x.name)
let method = fieldValue && x.type=="multipleRecordLinks" ? fieldValue.map(y => ({id: y.id})) : fieldValue
Object.assign(obj, {ix.name]: method})
})
await table.createRecordAsync(obj)
In this structure, “Sample” is the table name, “Trans 10” is the excluded field, and “Parent” is the name of the field that needs to contain the link to the original record. Parent is a linked field type, and will sometimes contain a value (which needs to be replaced) or will sometimes be blank (in which the most recent parent needs to be filled). We will use this data down the line to construct trees, in which all children can be linked down to child samples.
Fairly soon we’re going to get some dedicated Javascript assistance, but I would really like to get this one thing working to dramatically simplify our workflow in the interim.
Thanks!
Nareg
Could you please describe what exactly didn’t work? Did you receive an error message? If so, what’s the error? If there was no error, please describe in detail what did occur, and how that differs from your expectation.
Hi Justin,
I was able to figure it out. When the code was run as described in my previous post, the “Parent” field, where the original record was supposed to be linked was not being filled in correctly. It would always return the result that was stored from the original inherited sample, i.e. like a “grandparent”.
However, I was able to solve this by including “Parent” as an excluded field. Now, it would not copy the original record’s value, but instead replace it with the link to the selected record as intended.
Thanks for your help!
Best regards,
Nareg