Hi guys, sorry to bug you again but I tried to sav...
# suitescript
b
Hi guys, sorry to bug you again but I tried to save a document (that is already saved in the file cabinet) into a custom field of type "Document" called cust_test_attch using the document id value. But i am getting the error: "type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value 18112172 for the following field: cust_test_attch" Any ideas why this is happening? See the code below:
Copy code
const objRecord = record.load({
         type: record.Type.CUSTOMER,
         id: recId,
         isDynamic: true
      });

      objRecord.setValue({
        fieldId: 'cust_test_attch',
        value: fileId
      });

      objRecord.save({
        enableSourcing: true,
        ignoreMandatoryFields: true
      });
The fileId is something like 17673421.
e
@Berenice Domínguez check if passing the same value as string it works, if not make sure the id you are passing is actually the id of a file from the file cabinet. I would set a file in that field through the UI, save it and see how it looks, it this works, then I will empty the value and try with the same id via code, that should work.
🙏 1
b
Ok will try that now 🙂
Btw i tried the string approach and did not work, i am going to try the second suggestion.
That did not work either. 😞 I still get the same error: {"type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value 18112172 for the following field: cust_test_attch","stack":["anonymous(N/serverRecordService)","notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
e
Would you mind sharing the definition of your Document entity field? and also a screenshot of the file record you want to set? I want to see the URL, you can blur any sensitive data you do not want to show.
b
Of course, one second. 🙂
That is the document entity.
By the url do you mean the actual document url?
That?
e
Exactly! Were you able to set the same document through the UI? I am not sure why this is not working for you.
b
I am saving the file first, then grabbing the fileId to attach it to the customer record. file.isOnline = true; file.folder = 9999; fileId = file.save();
Through the UI you mean inside the customer record form using NS, right?
e
Oh, I see. Yes, I mean that. Could you please try with a file id that already exist in the file cabinet? comment the code you are using to save a new file, just hardcode the file id for testing purposes and see if you are able to set/save it.
b
I tried that too 😞
and got the same error.
e
but, are you able to save a file in that field through the user interface? (manually), if you are not able to do it there, it will not work via coding.
b
Yes i was able to save the file in that custom field
Hardcoded the values: const objRecord = record.load({ type: record.Type.CUSTOMER, id: 1154311, isDynamic: true }); objRecord.setValue({ fieldId: 'cust_test_attch', value: 18114880 }); objRecord.save({ enableSourcing: true, ignoreMandatoryFields: true });
e
Ha! your "cust_test_attach" seems incorrect, it should start with
custentity
b
Oh yeah that is just a fake name 😅 the one i am using actually is custentity_test_attach
🙂
Sorry about that.
e
haha no worries. I'm out of ideas but check this, open your customer record in edit mode (save before a file in that field), open the developer tools of your browser and type this:
nlapiGetFieldValue('custentity_test_attach')
try to use the same id you get from here in your code, it this does not work I do not know what is going on, sorry 😕
b
Ok, will try that! 🙂
Thank you sooo much!!! I really appreciate your time and help!
👌 1
e
Final thoughts, remove the enableSourcing key from the .save method.
🙌 1
b
ok
No it did not work, the custom field is empty and the document is saved under communication tab / files.
Thank you so much for your help! I really appreciate it. Now if i can take advaantage of your knowledge, do you know how to save under the communications tab / messages an email sent to a customer after they submit a webform? I saw in the documentation that using the record property like this should work: var records = new Object(); records['record'] = parsedId; records['recordtype'] = 'customer'; log.debug('records:::', records); var author = 10312026, options = { author : author, recipients : companyEmail, subject : emailSubject, body : emailBody, record : records }; email.send(options);
e
Yes, I think it should work, here you have an example in 1.0 version, the logic is very similar just the syntax is different: https://netsuite.custhelp.com/app/answers/detail/a_id/29329/kw/attach%20email%20on%20customer%20suitescript
I have not done this in a while but check this in 2.0, pay attention to the relatedRecords key: https://netsuite.custhelp.com/app/answers/detail/a_id/43754
b
HI
This did it! var records = {}; records.entityId = customerId;
and then
pass relatedRecords property to the options var. options = { author : author, recipients : companyEmail, subject : emailSubject, body : emailBody, relatedRecords : records }; email.send(options);
message has been deleted
e
Awesome! I'm glad this help. thanks for sharing the code 🙂
🙏 1
b
Hi eminero. 🙂 So I tried everything and i still get the error: INVALID_FLD_VALUE. Not sure if saving the value for the entity field type "Document" work, but i can't find documentation for this. Any other ideas of the type of value i need for that type of custom field? Sorry to bug you again tho. I appreciate your help!!!