I need a user event script where when a drop ship ...
# ask-stanley-ai
s
I need a user event script where when a drop ship PO is created for a certain vendor, the script compares the PO rate with the SO rate. What would be a good start to this?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** To create a User Event script that triggers when a drop ship Purchase Order (PO) is created for a certain vendor and compares the PO rate with the Sales Order (SO) rate, you would need to follow these steps: 1. Create a custom field on the Sales Order line item: This field will hold the rate of the item when the Sales Order is saved. This can be done through SuiteScript by writing a script that updates this custom field. 2. Create a User Event script that triggers on the creation of a Purchase Order: This script should be designed to trigger when a drop ship PO is created. In this script, you would need to: - Identify if the PO is a drop ship PO and if it is for the specified vendor. - Retrieve the related Sales Order and the custom field you created in step 1. - Compare the rate on the PO with the rate stored in the custom field on the SO. Here is a high-level pseudo-code example of what this might look like:
Copy code
pseudo
function beforeSubmit(context) {
  if (context.type !== context.UserEventType.CREATE) return;
  
  var newRecord = context.newRecord;
  var vendor = newRecord.getValue('entity');
  
  if (newRecord.getValue('custbody_drop_ship') && vendor === 'specifiedVendor') {
    var poRate = newRecord.getValue('rate');
    var soId = newRecord.getValue('createdfrom');
    var soRecord = record.load({type: 'salesorder', id: soId});
    var soRate = soRecord.getValue('custbody_rate');
    
    if (poRate !== soRate) {
      // Handle the discrepancy
    }
  }
}
Please note that this is a high-level example and you would need to adjust it to fit your specific needs. Also, you would need to replace 'custbody_drop_ship' and 'custbody_rate' with the actual IDs of your custom fields, and 'specifiedVendor' with the internal ID of your vendor. Remember to deploy the script and associate it with the Purchase Order record type.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859145343
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856270313
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851231098
Please provide your feedback on this answer.