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
Cloud AtlasCloud Atlas 

Javascript Running but not updating

Hello ,

I have the below JScript as a button.. Everytime I am clicking it, the page refreshes but nothing changes..
Can some one point out what am is missing in there..
I am building a WF on this.. so field update is necessary... 

Button is supposed to change the RT value from Claim to Risk and manipulate data in successive fields...
 
{!REQUIRESCRIPT("/soap/ajax/***/connection.js")}
var a = false;
if({!Case.Possible_Risk__c} != true)
a = confirm('Are you sure you want to change this from a Claim to a Risk?');
var recordType = sforce.connection.query('select id, name from recordtype where sobjecttype=\'Case\' and name = \'US Risk\'');
var recordTypeEMEA = sforce.connection.query('select id, name from recordtype where sobjecttype=\'Case\' and name = \'EMEA Risk\'');

var records = recordType.getArray("records");
/* alert('Check records' + records); */
var recordsE = recordTypeEMEA.getArray("records");
/* alert('Check recordsE' + recordsE); */

if(a)
{
var newRecords = [];

var c = new sforce.SObject("Case");
c.id = "{!Case.Id}";
c.Possible_Risk__c = true;  // Checkbox on which my WF will depend on//
c.Reason__c = 'Risk';
c.OwnerId = '{!$User.Id}';

/* alert('Inside IF, check for EMEA' + {!ISPICKVAL(Case.Region__c, 'EMEA')}); */

if ({!ISPICKVAL(Case.Region__c, 'EMEA')})
c.RecordTypeId = recordsE[0].Id;
else
c.RecordTypeId = records[0].Id;
newRecords.push(c);

result = sforce.connection.update(newRecords);
window.location.reload();
}


Any help is appreciated.
Thanks!
 
Brenda S FinnBrenda S Finn
I would suggest adding opening & closing braces for your if-else statements or put some line breaks after the if/else body. However, that it not your problem. I see two issues with your JS.

1. On line 26, you are referring to recordsE[0] and there is no recordsE object, you have a records object so it should read:

c.RecordTypeId = records[0].Id;

2. Line 33 is a closing brace for the if statement on 13 which is commented out so you need to either comment out line 33 or remove it.

Are you using firebug or another JS tool to help you debug your JS? It can be very helpful in determining if your JS has errors along with console.log statements in your JS.