Hi All,
I am relatively new to scripting and whilst I have managed to get some scirpts working I am getting a strange error which I can't figure out.
I set my script as a workflow (WF) action and have tested it as a button on a custom record and it works fine, I am now trying to incorporate it into another WF which controls a status field and will initiate the WF action at a relevant point, unfortunately when I do I get errors from netsuite regarding the GetName and SetName (In Bold Below) functions used to attach the Merge record to the custom record.
So the WF basically sets a status field depending on the data the user enters, as they submit the record the WF checks the data and sets a status accordingly, one of the status sets initiates another WF which run the code below.
The error I get is TypeError: Cannot call method "setName" of undefined (dsa_confirmation_merge.js#57)
function PSCPrint() { var newRec = nlapiGetNewRecord(); var assLocation = newRec.getFieldText('custrecord_dsa2_assessment_location'); //Get the field value of assessment location var last_name = newRec.getFieldValue('custrecord_dsa2_student_last_name'); //Capture Student Last Name var first_name = newRec.getFieldValue('custrecord_dsa2_student_first_name'); //Capture Student First Name var date_cap = newRec.getFieldValue('custrecord_dsa2_merge_todays_date'); //Capture Date if (assLocation=='AbilityNet DSA Centre London') { var mailRec = nlapiMergeRecord(95, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 95 (London) } else if (assLocation=='Ace Oxford') { var mailRec = nlapiMergeRecord(118, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 118 (Oxford) } else if (assLocation=='Eastleigh') { var mailRec = nlapiMergeRecord(119, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 119 (Eastleigh) } else if (assLocation=='Imperial College') { var mailRec = nlapiMergeRecord(120, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 120 (Imperial) } else if (assLocation=='RCA') { var mailRec = nlapiMergeRecord(122, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 122 (RCA) } else if (assLocation=='Treloars College Outreach Centre') { var mailRec = nlapiMergeRecord(121, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 121 (Treloard Outreach) } else if (assLocation=='Treloars Trailblazer Outreach Facility') { var mailRec = nlapiMergeRecord(121, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 121 (Treloars Trailblazer) } else if (assLocation=='Goldsmiths') { var mailRec = nlapiMergeRecord(123, 'customrecord_dsa_v2', newRec.getId()); //merges the record to the template with id 123 (Goldsmiths) } var file_name = mailRec<strong>.getName()</strong>; mailRec<strong>.setName</strong>(newRec.getId() + '_' + last_name + '_' + first_name + '_' + 'confirmation_letter' + '_' + date_cap + '.doc'); // ensures file name is unique by adding lastname_firstname_documentname_date, and set with the file extension .doc mailRec.setFolder(6747); //internal ID of the folder in your file cabinet to store the created documents var file_id = nlapiSubmitFile(mailRec); //saves file to the file cabinet nlapiAttachRecord('file', file_id, 'customrecord_dsa_v2', newRec.getId(), null); //Attaches the file to the current custom record nlapiSubmitField(newRec.getRecordType(), newRec.getId(), 'custrecord_dsa2_merge_confirmation_id', file_id); //Set the merged document link field on the original record. }