• Kaybee011
  • NEWBIE
  • 55 Points
  • Member since 2016

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

Need assistance with Javascript button that should convert record from Record type A to B.  If user clicks the Cancel on the Edit screen, the record is saved anyway.

How do I load the page back to previus view page if user Cancels?

Code below:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 
caseObj.RecordTypeId = '012D00000003I73'; 
var result = sforce.connection.update([caseObj]); 

if(result.success = 'true'){ 
parent.frames.location.replace("/"+caseObj.Id+"/e?retURL=%2F"+caseObj.Id+""); 
}else{ 
*I assume the window reload function here?*
}

*It goes without saying that I'm new to this*

Thanks in advance.
I ma new to salesforce. Can anyone please tell what exactly is a sales process and i twould be of great help if you can provide relavent documents.

I'm not sure how to accomplish this.  I have a javascript button Reject, but if someone decides to cancel rejecting the record, the Status still get changed to Rejected.  Where do I move the update code so that if they click Cancel on the Edit screen the Status won't change?

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 
{!requireScript("/soap/ajax/20.0/apex.js")} 

var changeObj = new sforce.SObject("Change__c");
changeObj.Id = '{!Change__c.Id}';

var profileName = '{!$Profile.Name}';
var roleName = '{!$UserRole.Name}';

var d=new Date().toISOString();;
/*var n=d.toJSON();*/

if(changeObj.StatusChange__c='Proposed')
{ 

//If current user’s profile is CW Pilot Dealer Portal User and Contact has accepted or Contact is a Dealer Portal User
if((profileName.indexOf("Dealer")!=-1)&&('{!Change__c.Contact_Accepted__c}'==true))
{
changeObj.Dealer_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Dealer_Rejected_Checkbox__c= true; //check the box 
/*changeObj.Dealer_Rejected_Date_Time__c="changeObj.Dealer_Rejected_Date_Time__c";*/
changeObj.Dealer_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';

window.parent.location='/apex/rejectChangeDealer?Id={!Change__c.Id}&retURL=/{!Change__c.Id}';

}else{

//If current user's profile is CW Pilot Dealer Portal User and Contact Accepted is not checked, throw an error 
if((profileName.indexOf("Dealer")!=-1)&&('{!Change__c.Contact_Accepted__c}' != true))
{ 
alert("Additional approvals/rejections are required before you can perform this action.");
}else{

//If current users profile is Customer Portal, fill in the current users name for Contact Rejected and fill in the current date and time 
if(profileName.indexOf("Customer")!=-1)
{
changeObj.Contact_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Contact_Rejected_Checkbox__c= true;
/*changeObj.Contact_Rejected_Date_Time__c="changeObj.Contact_Rejected_Date_Time__c";*/
changeObj.Contact_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';
alert("You have selected to reject this change.  Please fill in the Contact Rejected Comments in the Rejected Information section towards the bottom this Change record.")
window.parent.location.href="/{!Change__c.Id}" + "/e"; 

}else{

if((roleName.indexOf("Tier 2") != -1) || (roleName.indexOf("Product Support Manager") != -1)) 
{
if(('{!Change__c.Contact_Accepted__c}'==true) && ('{!Change__c.Dealer_Accepted__c}'==true))
{
changeObj.Change_Manager_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Change_Manager_Rejected_Checkbox__c=true;
/*changeObj.Change_Manager_Rejected_Date_Time__c="changeObj.Change_Manager_Rejected_Date_Time__c";*/
changeObj.Change_Manager_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';
window.parent.location='/apex/rejectChangeChgMgr?Id={!Change__c.Id}&retURL=/{!Change__c.Id}';
}else{
alert("Additional approvals/rejections are required before you can perform this action.");
}
}else{
alert("You are not authorized to perform this action.");
}}}}
}else{
alert("Status needs to be Planned before you approve of this change.");
}

if(changeObj.StatusChange__c == 'Approved')
{
alert("Change has already been Approved.");
}else{

if((changeObj.StatusChange__c=='Implemented') || (changeObj.StatusChange__c=='Completed'))
{
alert("Change has already been Implemented. Approvals are no longer needed.");
}}

var result = sforce.connection.update([changeObj]);
if (result[0].success=='false')
{
alert(result[0].errors.message);
}

 

  • August 26, 2013
  • Like
  • 0