When importing file data into a table, I want to import the file name at the same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 06:32 PM
please teach me.
I created a custom table. This is u_10_31t.
Using an import set,
Insert data into columns short_description1 and short_description2 of that table.
At the same time, I want to insert the value of the file used in the import set into the column short_description4.
I rewrote the code, but short_description4 is either an error or blank.
-------------------------
・Write
target.u_short_description4 = new GlideSysAttachment('file.name');
・Error
com.glide.ui.SysAttachment@9328d4
or
・Write
var target = new GlideRecord('sys_attachment') ;
target.addQuery('file_name');
target.query();
gr.getDisplayValue('short_description4',file_name);
・Error
blank
-------------------------
Only one file is imported every time.
I would like to know what code to write to insert the attachment file name into column short_description4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 11:46 PM
Hi @Komazawa Akane ,
Create new transform map on your custom table u_10_31t.
In onBefore transform map script write below script
(function runTransformScript(source, map, log, target) {
var fileName = source.getValue('file.name'); // 'file.name' is the source field name.
target.u_short_description4 = fileName;
})(source, map, log, target);
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2023 08:14 AM
Thank you for your kindly support.
but I wrote yours in onBefore transform map script, but short_description4 was blank in u_10.31T table...
Maybe I thought that the attachment file was not extended to the import set table...Just I guess.
This following I found in ServiceNow's Dogs.
--------------------
SNow
https://docs.servicenow.com/ja-JP/bundle/tokyo-application-development/page/script/server-scripting/...
var target = new GlideRecord('attachment') ;
target.addQuery('filename');
target.query();
--------------------
How about this method?
It would be helpful if you could teach me the code to pass the data of sys_attachment table to u_10.31T table after making the query.