Help

Create Records for Multiple Templates: Lookup Field Error

Topic Labels: Extensions
Solved
Jump to Solution
639 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Tom_Glatt
6 - Interface Innovator
6 - Interface Innovator

In my template table I have a lookup field that is formatted as currency. In the child table I have the same field with the same formatting, but I'm getting an "root must be a number" error when I run the script. I'm guessing this needs to be modified in some way because of the lookup field issue, but I'm not sure how:

 

'templateRate': c.getCellValue('Rate')
1 Solution

Accepted Solutions
Stephen_Orr1
10 - Mercury
10 - Mercury

Lookup field values are returned as arrays. 

try

'templateRate': c.getCellValue('Rate')[0],

Fun facts: It can look weird in the console at first because arrays are objects in Javascript which can have extra properties added to them other than the values stored in the array (for example, lookup field arrays have linkedRecordIds and valuesByLinkedRecordId properties added to them). You can see this by running console.log(typeof []) which outputs "object" and console.log(Array.isArray([])) which outputs true.

 

 

 

See Solution in Thread

3 Replies 3
Tom_Glatt
6 - Interface Innovator
6 - Interface Innovator

This may help better explain my question ... This the excerpt from script where the value from the template. The lines in question are in bold. The Rate field in the template is a lookup with the result formatted as currency. The Rate field in the child (target) table is a currency field. 

 

// Filter the template records to match the selected type & add the parent ID to the map
let types = typesRecords.map(c => ({
'child': [c],
'childName': c.getCellValue(childFieldInTemplate),
'templateTypes': c.getCellValue(templateType).map(x => x.id),
'templateOrder': c.getCellValue(templateOrder),
'templateQuantity': c.getCellValue('Quantity'),
'templateSubtasks': c.getCellValue('Subtasks'),
'templateModule': c.getCellValue('Module'),
'templateRate': c.getCellValue('Rate'),
'templateType': {name: c.getCellValueAsString('Type')}
})).filter(x => x.templateTypes.includes(parentType[0].id))

// Create the child records and sort them so that they are in order
let createRecords = types.map(c => ({
fields: {
[childNameInChild.name]: c.childName,
[parentFieldInChild.name]: [selectedEvent],
[childOrder.name]: c.templateOrder,
'Quantity': c.templateQuantity,
'Subtasks': c.templateSubtasks,
'Module': c.templateModule,
'Rate': c.templateRate,
'Type': c.templateType
}
Stephen_Orr1
10 - Mercury
10 - Mercury

Lookup field values are returned as arrays. 

try

'templateRate': c.getCellValue('Rate')[0],

Fun facts: It can look weird in the console at first because arrays are objects in Javascript which can have extra properties added to them other than the values stored in the array (for example, lookup field arrays have linkedRecordIds and valuesByLinkedRecordId properties added to them). You can see this by running console.log(typeof []) which outputs "object" and console.log(Array.isArray([])) which outputs true.

 

 

 

Tom_Glatt
6 - Interface Innovator
6 - Interface Innovator

That was it. Thank you! I'm not skilled in JS - so I truly appreciate the assistance, and the added "fun facts." I'll also review the link you sent. Learning something new is never a bad thing.