function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
crmexpertcrmexpert 

why is my code not working?

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!requireScript("/soap/ajax/13.0/apex.js")}
var connection = sforce.connection;

var opp = new sforce.SObject("Ord__c");
alert(opp);

if ((opp.Status__c == "Submitted")  ||   (opp.Status__c== "Completed") ||  (opp.Status__c== "Shipping In Progress"))
{
      alert("The record cannot be submitted.  Only records that have the status ‘New Order’ may be submitted");
}
else
{

opp.Status__c="Submitted";
connection.update([opp]);
alert("Done.");
      
}
SteveBowerSteveBower

There is much confusion here.

 

In no particular order:

 

1. You're using version 8 of the Ajax toolkit.  If this is new code, why not use the most recent version.

2. What are you trying to accomplish?

If you are creating a new Ord__c record, then why are you testing to see what the Status__c is?  After all, *you* just created the record.

3. Remember, you just created a Javascript object, not a Salesforce record.  So, it's not in Salesforce yet, so you can't update it.  You can "insert" it if you want.

4. It seems to me that you're trying to do some sort of trigger functionality.  If so, you have to use Apex and not Ajax.

5. You might be able to accomplish what you're trying to do (which is still unclear to me) via Validation rules instead of code.

6. Including "/soap/ajax/13.0/apex.js" gives your Javascript access to Apex methods via the "execute"method.  You're not using that anywhere?

 

All in all, I think it would be best if you wrote down an English Use Case of what you are trying to accomplish and post it here.  Perhaps some suggestions on approach would be forthcoming.

 

Best, Steve.

NBlasgenNBlasgen

I also have no idea what you're trying to do here (I've never seen a Javascript library for direct API access but I could believe it), but just from a Javascript standpoint:

 

var str='';

for (object in opp) { str = str + '\n' + object + ': ' + opp[object]; }

alert(str);