This topic contains 2 replies, has 0 voices, and was last updated by CFong 8 years, 4 months ago.
-
AuthorPosts
-
June 28, 2016 at 10:33 am #6368
CFongI have a relatively simple script which is triggered by a user action on an item fulfillment.
For testing purposes, and occasionally during day to day operations, the fulfillment record needs to be deleted. Before I added my SS I would get a screen saying that the record was deleted and a button to take me back to the sales order. Now I get a notice from SuiteScript saying that the record doesn’t exist, and the “go back” button takes me to the item fulfillment page.
Now if I go back to the originating Sales Order, the fulfillment is gone from the related records.
Is there a “best practice” to check for the existence of a record to use for conditional running of the script?
My current script below:
Code:
function copy_shipping_carrier_to_so_record() {/*
*
* TODO – Make a conditional test to stop the script from running if there is no record and/or the itemfulfillment record is being deleted.
*
*/// After submit of Item Fulfillment Record
// Load Item fulfillment record to access the fields
var record = nlapiLoadRecord(‘itemfulfillment’, nlapiGetRecordId());if (Boolean(record) == false){
return
} else {
var carrier = record.getFieldValue(‘custbody_ozlink_shipping_carrier’); // Get carrier valuevar related_so = record.getFieldValue(‘createdfrom’); // Get related record Sales order internal ID
var so_record = nlapiLoadRecord(‘salesorder’, related_so); // Load Sales Order record – based on the related record via NS internal ID
so_record.setFieldValue(‘custbody_ozlink_shipping_carrier’, carrier); // Set Sales Order record value
nlapiSubmitRecord(so_record, null, true); // Submit/save the record
var customer = so_record.getFieldValue(‘entity’); // get the internal ID of the customer record
var tracking_email = nlapiCreateEmailMerger(4); // Start the email merger and set the template
tracking_email.setTransaction(related_so); // retrieve the sales order to merge with the templatevar send_ready = tracking_email.merge(); // generate the merger
var tracking_body = send_ready.getBody(); // merge the body
var tracking_sub = send_ready.getSubject(); // merge the subjectvar tracking_email_send = nlapiSendEmail(19585, customer, tracking_sub, tracking_body, null, ‘caleb@calpetrx.com’, null, null, null, false, 19585); // Send the email!
}
}
This is a cached copy. Click here to see the original post. -
June 28, 2016 at 11:40 am #6369
Olivier Gagnon NCDo you mean if(type!=’delete’)? If so, check the Help and see about the ‘type’ entry parameter.
-
June 28, 2016 at 5:55 pm #6370
CFongOriginally posted by Olivier Gagnon NC
View Post
Do you mean if(type!=’delete’)? If so, check the Help and see about the ‘type’ entry parameter.
Thanks Olivier Gagnon NC! While I was troubleshooting another issue with NS support they also clued me in to the “type” parameter. It worked a charm!
For those that may come to this later here’s how the current version looks – I took out some of the comments that are only interesting to myself:
Code:
function copy_shipping_carrier_to_so_record(type) {// After submit of Item Fulfillment Record
if (type == ‘create’ || type == ‘edit’){ // verifies record exists or has been edited
var record = nlapiLoadRecord(‘itemfulfillment’, nlapiGetRecordId()); // Load Item fulfillment record to enable access the field valuesvar carrier = record.getFieldValue(‘custbody_ozlink_shipping_carrier’); // Get carrier value
var related_so = record.getFieldValue(‘createdfrom’); // Get related record Sales order internal ID value
var so_record = nlapiLoadRecord(‘salesorder’, related_so); // Load a Sales Order record – based on the related record via NS internal ID
so_record.setFieldValue(‘custbody_ozlink_shipping_carrier’, carrier); // Set Sales Order record value
nlapiSubmitRecord(so_record, null, true); // Submit/save the record (which is still “loaded” until we load a new record)
var customer = so_record.getFieldValue(‘entity’); // get the internal ID of the customer record
var tracking_email = nlapiCreateEmailMerger(4); // Start the email merger and set the template
tracking_email.setTransaction(related_so); // retrieve the sales order to merge with the templatevar send_ready = tracking_email.merge(); // generate the merger
var tracking_body = send_ready.getBody(); // merge the body
var tracking_sub = send_ready.getSubject(); // merge the subjectvar tracking_email_send = nlapiSendEmail(19585, customer, tracking_sub, tracking_body, null, ‘caleb@calpetrx.com’, null, null, true, false, 19585); // Send the email! and alert someone if the email bounces back
}
} -
AuthorPosts
You must be logged in to reply to this topic.