• dquirke
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi All,

 

I am trying to modify a Custom S control to look at two separate objects as validation before a sales order is created. The original part of the code was as follows:

 

function success(qr) { 
//Create SO Header 
var it = new sforce.QueryResultIterator(qr); 
var OppId = "{!Opportunity.Id}"; 
var AccountId = "{!Account.Id}"; 
var records = qr.getArray("records"); 
while(it.hasNext()){ 
var record = it.next(); 

if (record.PBSI__hasSO__c == "1") 

window.parent.location.href="/" + OppId; 
failure("This opportunity has already been converted to a sales order!"); 

else 

var salesorder = new sforce.SObject("PBSI__PBSI_Sales_Order__c"); 
salesorder.PBSI__Customer__c = record.AccountId; 
salesorder.PBSI__Lead_Source__c = record.LeadSource; 
salesorder.PBSI__Created_From__c = record.Name; 
salesorder.PBSI__Opportunity__c = record.Id; 
salesorder.PBSI__Customer_Purchase_Order__c = record.PBSI__Customer_PO__c; 
salesorder.PBSI__Order_Discount__c=record.PBSI__Discount__c; 

result = sforce.connection.create([salesorder]); 

salesorder.id = result[0].id; 

 

This works fine. However, I am trying to add in a section to get it to look at the "account status" field on the account and if it has a value of either "On Hold" or "Gone Legal" it will also fail to create a sales order.

 

I came up with the following:

 

function success(qr) { 
//Create SO Header 
var it = new sforce.QueryResultIterator(qr); 
var OppId = "{!Opportunity.Id}"; 
var AccountId = "{!Account.Id}"; 
var records = qr.getArray("records"); 
while(it.hasNext()){ 
var record = it.next(); 

if (record.PBSI__hasSO__c == "1") 

window.parent.location.href="/" + OppId; 
failure("This opportunity has already been converted to a sales order!"); 

if (record.c2g__CODACreditStatus__c == "On Hold") 

window.parent.location.href="/" + AccountId; 
failure("Oi Dingbat, This account is On Hold!"); 


else 

var salesorder = new sforce.SObject("PBSI__PBSI_Sales_Order__c"); 
salesorder.PBSI__Customer__c = record.AccountId; 
salesorder.PBSI__Lead_Source__c = record.LeadSource; 
salesorder.PBSI__Created_From__c = record.Name; 
salesorder.PBSI__Opportunity__c = record.Id; 
salesorder.PBSI__Customer_Purchase_Order__c = record.PBSI__Customer_PO__c; 
salesorder.PBSI__Order_Discount__c=record.PBSI__Discount__c; 

result = sforce.connection.create([salesorder]); 
salesorder.id = result[0].id; 

 

As you can see I defined the "AccountId" variable but I am not a javascript programmer so I've obviously gone wrong somewhere.

 

Any help much appreciated.

 

All the best


David Quirke

 

 

Hi All,

 

I am trying to modify a Custom S control to look at two separate objects as validation before a sales order is created. The original part of the code was as follows:

 

function success(qr) { 
//Create SO Header 
var it = new sforce.QueryResultIterator(qr); 
var OppId = "{!Opportunity.Id}"; 
var AccountId = "{!Account.Id}"; 
var records = qr.getArray("records"); 
while(it.hasNext()){ 
var record = it.next(); 

if (record.PBSI__hasSO__c == "1") 

window.parent.location.href="/" + OppId; 
failure("This opportunity has already been converted to a sales order!"); 

else 

var salesorder = new sforce.SObject("PBSI__PBSI_Sales_Order__c"); 
salesorder.PBSI__Customer__c = record.AccountId; 
salesorder.PBSI__Lead_Source__c = record.LeadSource; 
salesorder.PBSI__Created_From__c = record.Name; 
salesorder.PBSI__Opportunity__c = record.Id; 
salesorder.PBSI__Customer_Purchase_Order__c = record.PBSI__Customer_PO__c; 
salesorder.PBSI__Order_Discount__c=record.PBSI__Discount__c; 

result = sforce.connection.create([salesorder]); 

salesorder.id = result[0].id; 

 

This works fine. However, I am trying to add in a section to get it to look at the "account status" field on the account and if it has a value of either "On Hold" or "Gone Legal" it will also fail to create a sales order.

 

I came up with the following:

 

function success(qr) { 
//Create SO Header 
var it = new sforce.QueryResultIterator(qr); 
var OppId = "{!Opportunity.Id}"; 
var AccountId = "{!Account.Id}"; 
var records = qr.getArray("records"); 
while(it.hasNext()){ 
var record = it.next(); 

if (record.PBSI__hasSO__c == "1") 

window.parent.location.href="/" + OppId; 
failure("This opportunity has already been converted to a sales order!"); 

if (record.c2g__CODACreditStatus__c == "On Hold") 

window.parent.location.href="/" + AccountId; 
failure("Oi Dingbat, This account is On Hold!"); 


else 

var salesorder = new sforce.SObject("PBSI__PBSI_Sales_Order__c"); 
salesorder.PBSI__Customer__c = record.AccountId; 
salesorder.PBSI__Lead_Source__c = record.LeadSource; 
salesorder.PBSI__Created_From__c = record.Name; 
salesorder.PBSI__Opportunity__c = record.Id; 
salesorder.PBSI__Customer_Purchase_Order__c = record.PBSI__Customer_PO__c; 
salesorder.PBSI__Order_Discount__c=record.PBSI__Discount__c; 

result = sforce.connection.create([salesorder]); 
salesorder.id = result[0].id; 

 

As you can see I defined the "AccountId" variable but I am not a javascript programmer so I've obviously gone wrong somewhere.

 

Any help much appreciated.

 

All the best


David Quirke