Skip to content

Instantly share code, notes, and snippets.

@smcllns
Created June 11, 2014 20:59
Show Gist options
  • Save smcllns/b2aef40f2a64ec683b6b to your computer and use it in GitHub Desktop.
Save smcllns/b2aef40f2a64ec683b6b to your computer and use it in GitHub Desktop.
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var q1 = sforce.connection.query("SELECT Id, Name, PBSI__Item__r.Id, PBSI__Total_Quantity__c FROM PBSI__Lot__c where PBSI__Item__r.Name ='" + item + "' AND PBSI__Total_Quantity__c > 0.1");
var lots = q1.getArray("records");
var inserts = []
for (var i=0; i<lots.length; i++) {
var newLine = new sforce.SObject("PBSI__Count_Line__c");
newLine.PBSI__Count_Journal__c = '{!PBSI__Count_Journal__c.Id}';
newLine.PBSI__Item__c = lots[i].PBSI__Item__r.Id;
newLine.PBSI__Lot__c = lots[i].Id;
newLine.PBSI__Quantity_In_Inventory__c = Math.abs(parseFloat(lots[i].PBSI__Total_Quantity__c).toFixed(2));
inserts.push(newLine)
}
var result=sforce.connection.create(inserts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment