Is it possible to set an Image type field on an it...
# suitescript
s
Is it possible to set an Image type field on an item with a map/reduce Suite Script? I've tried every possible combination with setText and setValue with the url and internalid of the image in the cabinet. Both in an array and not.
b
share the code
s
Copy code
```UpdateFields({ field, url, fdid }) {
			//const fld = { fieldId: field, ignoreFieldChange: false }
			const f = this.item.getField({ fieldId: field })
			Common.netsuiteIsAnnoying(
				() => this.item.setValue({ fieldId: f.id, value: /*0*/ fdid }),
				() => this.item.setValue({ fieldId: f.id, value: /*1*/ fdid.toString() }),
				() => this.item.setValue({ fieldId: f.id, value: /*2*/ [fdid] }),
				() => this.item.setValue({ fieldId: f.id, value: /*3*/ [fdid.toString()] }),
				() => this.item.setValue({ fieldId: f.id, value: /*4*/ url }),
				() => this.item.setValue({ fieldId: f.id, value: /*5*/ [url] }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*6*/ fdid }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*7*/ fdid.toString() }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*8*/ [fdid] }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*9*/ [fdid.toString()] }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*10*/ url }),
				() =>  this.item.setText({ fieldId: f.id, text:  /*11*/ [url] })
			)
		}
Copy code
netsuiteIsAnnoying: (...funcs) => funcs.forEach((func, i) => {
			try {
				func()
				log.debug({ title: i+'', details: 'might have worked' })
			} catch (error) {
				log.debug({ title: i+'', details: 'didnt work' })
				log.debug({ title: error.name, details: error.message })
			}
		})
thats what it looks like right now haha
b
um, thats gonna be equivalent to
Copy code
() =>  this.item.setText({ fieldId: f.id, text:  /*11*/ [url] })
which is wrong
just use setValue once, and use the internalid of the image as the value
s
with that function in my common mod I catch all the errors it throws.
How do you set a Image type field ?
b
internal id of the image
s
The object UpateFields get I have the internalid, url and full path. That function in my Common was an attempt to find a method that wouldn't throw an error.
with setValue ?
b
you can use either, but setValue is usually best
s
I get invalid ref or key.. could it be a folder permission possibly? theres a method before this one that creates the dir tree then the file.
b
you shouldnt get permission issues unless you are scheduling your map reduce script without the suitescript scheduling permission
you shouldnt be making complications for yourself
make a simple script
set the image to an image that already exists in a folder without permission issues
s
I have another method like this one that sets a text field with the url and that one works fine. It's just that Image Type field.
Well you've answered my question thought. setValue with the internalid. I'll go try an image id that's been in the file cabinet for a while and maybe make a json file with the mappings and update the Image Fields in a separate mr script. Thanks
b
what you were doing before was overwriting the field multiple times
so only the last one really mattered
your experience with the image url also sounds strange
use Field.getSelectOptions to see what your text options are supposed to look like
s
Yea that was an attempt to find a method that didn't try an error to find the right method. Nope the urls are fine. It's just that Image field thats giving me trouble.
first time I tried [{text: <filename>, value: <internalid>}] as the value
b
image fields dont use urls to set text
s
No I have another field appened with _url that's just a text field I'm using for another purpose.
b
Copy code
() =>  this.item.setText({ fieldId: f.id, text:  /*10*/ url }),
never stood a chance, the text for the select option is not a url
use Field.getSelectOptions to see what your text options are supposed to look like
s
that method worked for the hidden text field I'm using for templates. I was just having trouble with the Image type field.
b
different fields types use text different ways
select type fields like image field must have text that matches one of the select options
s
So if the select option you want is a svg file you just created in the file cabinet is would be the file name? or the internal id that was returned once saved that should be used with setValue?
b
use the documentation i listed to find out what your options are
s
ok