I am using nlapiCreateCSVImport() on my script. fo...
# suitescript
v
I am using nlapiCreateCSVImport() on my script. for the property setMapping(), what should i give? I tried with the file id that i saved. But it shows error. Could anyone please help?
n
Provide the ID of the saved CSV import.
v
function process(email) { try { var attachments = email.getAttachments(); nlapiLogExecution('DEBUG','attachments',attachments); for (var indexAttachment in attachments) { var attachment = attachments[indexAttachment] var fileType = attachment.getType(); nlapiLogExecution('DEBUG','indexAttachment', attachment); nlapiLogExecution('DEBUG','fileType',fileType); if (fileType === 'MISCBINARY'){ attachment.setFolder(-15); attachment.setIsOnline(true); var attachmentFileID = nlapiSubmitFile(attachment); nlapiLogExecution('DEBUG','attachmentFileID',attachmentFileID); var attachmentFileLoad = nlapiLoadFile(attachmentFileID); nlapiLogExecution('DEBUG','attachmentFileLoad',attachmentFileLoad.getId()); var job = nlapiCreateCSVImport(); nlapiLogExecution('DEBUG','job1',job); job.setMapping(attachment); nlapiLogExecution('DEBUG','job2',job); job.setPrimaryFile(attachmentFileLoad); nlapiLogExecution('DEBUG','job3',job); job.setOption("jobName", "jobImport"); nlapiLogExecution('DEBUG','job4',job); var jobId = nlapiSubmitCSVImport(job); nlapiLogExecution('DEBUG','jobId',jobId); } } }catch(e){ nlapiLogExecution('DEBUG','error', e); } }
This is my code.
what is there in this code?
n
What do you mean? And why aren't you using SuiteScript 2.0?
For the mapping, you need to provide the ID of your saved CSV import. You will need to create and save a CSV import.
From the docs: setMapping(savedImport) Sets the name of the saved import map to be used for an import, by referencing the internal ID or script ID of the import map.
Check documentation for nlobjCSVImport
v
its 1.0 only for some reasons
if you have any example could you please share?
i had gone thru the documentation also, i am not able to succeed
n
For the system to import the file it needs to know the file and the "saved csv import" id. How else would it know what you're importing the CSV as and mapping to? You do not appear to include that detail in your script. I'm not familiar with writing this as SS1.0 so you would need to go back to the documentation, I've only ever done it in SS2.
I just looked at the docs for you, it looks like setMapping may be expecting the saved csv import id, you appear to be putting the attachment in there for reasons I cannot even guess 😄 You will need to create a CSV import through the UI and preferably give it a custom id. As an example of what one of those might look like got to (see the image):
The documentation is clear on this:
see the mapping mappingFileId in the image above.
Also you need to be careful relying on "MISCBINARY" I'd be inclined to look at the attachment name for .csv / .CSV too.
Since you read the docs you probably already know this but:
v
THank you sir now i got it,
getting this below error Code: NLAPISUBMITCSVIMPORT_IS_ONLY_SUPPORTED_IN_SCHEDULED_RESTLET_AND_BUNDLE_INSTALLATION_SCRIPTS Details: nlapiSubmitCSVImport is only supported in Scheduled, RESTlet and Bundle Installation Scripts.
now trying to use nlapischedulescript. is it correct?
n
I highlighted in the docs the warning for you. It's not telling you to use that api call it's saying you can only use the csv import api call from those script types...
v
yes thank you sir, but i am new to netsuite so its all trial and error i am doing.
i have a question, in nlapischedulescript what shoulbe the parameters of that function?
n
Sorry, I don't know without looking at the documents. You realise that it's to start a scheduled script though? Not sure how that'll help you...