• Steve Huse
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 14
    Replies
Hi,

We have a custom Javascript button in our opportunity which creates a case and carries some of the opportunity detail across into the case as it does so.

I have a checkbox field in the opportunity and another in the case, and I want the below code to check the checkbox in the new case being created if the checkbox in the opportunity was checked.

I've tried inserting the line in bold below, but this doesn't work.

Can anyone help here?

TIA
Steve


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

var status = "{!Opportunity.StageName}";

if (
"{!Opportunity.Type}" != "Maintenance - New Agreement" &&
"{!Opportunity.Type}" != "Maintenance - Agreement Renewal" &&
"{!Opportunity.Type}" != "Maintenance - Resi MBF"
){

if (status == "Closed Won") {
var caseToCreate = new sforce.SObject("Case");
caseToCreate.AccountId = "{!Opportunity.AccountId}";
caseToCreate.Type = "{!Opportunity.Type}";
caseToCreate.Subject = "{!Opportunity.Name}";
caseToCreate.Origin = "Converted Opportunity";
caseToCreate.Description = "{!Opportunity.Requirement__c}";
caseToCreate.Related_Opportunity__C = "{!Opportunity.Id}";
caseToCreate.ContactId = "{!Opportunity.Opportunity_ContactId__c}";
caseToCreate.RecordTypeId = "01230000001DNJc";
caseToCreate.Case_Value__c = "{!TEXT(Opportunity.Amount)}";
caseToCreate.Case_Parts_Required__c = "{!Opportunity.Opp_Parts_Required__c}";

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

if(result[0].success == "true"){
alert("Case has been created.");
}
else{
alert("Error: " + result[0].errors.message);
}

} else {
alert(
"Opportunity must be won " +
"before a case can be created."
);
}
} else
alert(
"A case cannot be created for maintenance opportunities, " +
"other than ad-hoc maintenance visits. " +
"For maintenance opportunites, please use the " +
"Create Contract button."
);

Hi all,

 

We use the following code behind a custom button that's displayed on our opp detail page to automatically create a case.  We're using Professional Edition, so we don't have Apex available to us for this to happen automatically when the opp stage is changed to closed won.

 

You can see below that we're using an IF statement to only create the case if the opp stage is closed won, and to alert the user if otherwise.

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
   var c = new sforce.SObject("Case");
   c.AccountId = "{!Opportunity.AccountId}";
   c.Type = "{!Opportunity.Type}";
   c.Subject = "{!Opportunity.Name}";
   c.Origin = "Converted Opportunity";
   c.Description = "{!Opportunity.Requirement__c}";
   c.ContactId = "{!Opportunity.Opportunity_ContactId__c}";

   newRecords.push(c);

   result = sforce.connection.create(newRecords);
   alert ('Case has been created.');
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

I need to complicate this further with another IF statement, but not sure how to do so ... here's what we need:

 

We still need the case only to be created if the opp stage = closed won, and to alert the user if otherwise.

 

We have 6 opp types (we'll call them types 1 to 6), and in addition to the above IF statement, we also need the button to create the case if opp type = 1, 2, 3 or 4, but to alert 'A case cannot be created for opportunity types 5 or 6.' (and not create the case) if the opp type = 5 or 6.

 

Can anyone help me with a tweak to my button code to achieve this?

 

Thanks in advance.

 

Steve

Hi all,

 

We use the following code behind a custom button that's displayed on our opp detail page to automatically create a case.  We're using Professional Edition, so we don't have Apex available to us for this to happen automatically when the opp stage is changed to closed won.

 

You can see below that we're using an IF statement to only create the case if the opp stage is closed won, and to alert the user if otherwise.

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
   var c = new sforce.SObject("Case");
   c.AccountId = "{!Opportunity.AccountId}";
   c.Type = "{!Opportunity.Type}";
   c.Subject = "{!Opportunity.Name}";
   c.Origin = "Converted Opportunity";
   c.Description = "{!Opportunity.Requirement__c}";
   c.ContactId = "{!Opportunity.Opportunity_ContactId__c}";

   newRecords.push(c);

   result = sforce.connection.create(newRecords);
   alert ('Case has been created.');
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

I need to complicate this further with another IF statement, but not sure how to do so ... here's what we need:

 

We still need the case only to be created if the opp stage = closed won, and to alert the user if otherwise.

 

We have 6 opp types (we'll call them types 1 to 6), and in addition to the above IF statement, we also need the button to create the case if opp type = 1, 2, 3 or 4, but to alert 'A case cannot be created for opportunity types 5 or 6.' (and not create the case) if the opp type = 5 or 6.

 

Can anyone help me with a tweak to my button code to achieve this?

 

Thanks in advance.

 

Steve

Hi all,

 

I've struggled with this for a while and welcome any advice.

 

I want to place a custom button in opportunities (detail page) that, providing the opp stage is 'Closed Won' creates a case, copying a number of opp fields across into the case fields as it does so.

 

I currently have two custom buttons on the page that I'm testing ... both using Onclick Javascript.

 

HERE'S THE CODE BEHIND THE FIRST ONE:

if ("{!Opportunity.StageName}" == 'Closed Won')

{location.href = "/500/e?retURL=%2F500%2Fo

&cas4={!Account.Name}

&cas3={!Opportunity.Opportunity_Contact__c}

&cas5={!Opportunity.Type}

&cas11={!'Converted Opportunity'}

&cas14={!Opportunity.Name}

&cas15={!Opportunity.Requirement__c}

&retURL=/{!Opportunity.Id}&saveURL=/{!Opportunity.Id}";}

else

{alert('Opportunity must be won before a case can be created.'); }

 

What works:

  • The 'new case' page is launched and the fields are populated.

What doesn't work:

  • It doesn't always copy the full content of each field across ... i.e. an opportunity account name of 'ABC Construction Ltd' only populates as 'ABC' in the account name field on the case screen.
  • It requires the user to click the Save button after the fields have been populated.

 

HERE'S THE CODE BEHIND THE SECOND ONE:

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
var c = new sforce.SObject("Case");
c.AccountId = "{!Opportunity.AccountId}";
c.Contact = "{!Opportunity.Opportunity_Contact__c}";   <-------- Problem arises when other fields are included.
//add any other related fields you like

newRecords.push(c);

result = sforce.connection.create(newRecords);
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

What works:

  • Providing the line in red is left out, the button works fine.

What doesn't work:

  • As soon as I try to include any additional fields to carry across from the opp to the case, the button no longer works ... no case is created at all.

 

Can anyone tell me which code is best, or provide some guidance as to how to tweak either of the existing codes so that they work in the way I'd like them to?

 

Sorry for the long post!

 

Regards


Steve

Hi all,

 

I've struggled with this for a while and welcome any advice.

 

I want to place a custom button in opportunities (detail page) that, providing the opp stage is 'Closed Won' creates a case, copying a number of opp fields across into the case fields as it does so.

 

I currently have two custom buttons on the page that I'm testing ... both using Onclick Javascript.

 

HERE'S THE CODE BEHIND THE FIRST ONE:

if ("{!Opportunity.StageName}" == 'Closed Won')

{location.href = "/500/e?retURL=%2F500%2Fo

&cas4={!Account.Name}

&cas3={!Opportunity.Opportunity_Contact__c}

&cas5={!Opportunity.Type}

&cas11={!'Converted Opportunity'}

&cas14={!Opportunity.Name}

&cas15={!Opportunity.Requirement__c}

&retURL=/{!Opportunity.Id}&saveURL=/{!Opportunity.Id}";}

else

{alert('Opportunity must be won before a case can be created.'); }

 

What works:

  • The 'new case' page is launched and the fields are populated.

What doesn't work:

  • It doesn't always copy the full content of each field across ... i.e. an opportunity account name of 'ABC Construction Ltd' only populates as 'ABC' in the account name field on the case screen.
  • It requires the user to click the Save button after the fields have been populated.

 

HERE'S THE CODE BEHIND THE SECOND ONE:

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
var c = new sforce.SObject("Case");
c.AccountId = "{!Opportunity.AccountId}";
c.Contact = "{!Opportunity.Opportunity_Contact__c}";   <-------- Problem arises when other fields are included.
//add any other related fields you like

newRecords.push(c);

result = sforce.connection.create(newRecords);
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

What works:

  • Providing the line in red is left out, the button works fine.

What doesn't work:

  • As soon as I try to include any additional fields to carry across from the opp to the case, the button no longer works ... no case is created at all.

 

Can anyone tell me which code is best, or provide some guidance as to how to tweak either of the existing codes so that they work in the way I'd like them to?

 

Sorry for the long post!

 

Regards


Steve

 

Hi all,

 

We use web-to-lead, which generates lots of enquiries from outside of our area of coverage (despite our area of coverage being clearly stipulated on all of our contact pages!).

 

Out of courtesy, before deleting a lead who's outside of our area, I'd like a button (in Leads) that sends them a templated email saying 'Thanks for your enquiry but sorry, you are outside of our coverage area (blah blah)'.

 

I'm fine with creating custom buttons, but could use some code to create and send the email.  Ideally the email will contain a couple of lead mergefields and be created and sent on a single click (I don't need to review it).

 

I'm conversant with creating email templates.

 

Can anyone give me some guidance as to the best button code to pull this action together please?

 

Thanks in advance.


Steve

 

PS:  It would be even better if the button could email the lead and then delete them?

Hi All,

 

I'm hoping that someone can help me with this?

 

I want to create a custom button in Opps that creates a new case, providing the Opp is 'closed won'.

If the Opp is not 'closed won', then I need it to alert "Opp must be won to create case".

 

I've created a button using 'Content Source = URL' which creates a new case and populates the new case fields with data from the related Opp fields (see code below), but now that I want this to be conditional on the related Opp being closed won, it seems I need to make the button OnClick Javascript and use some Javascript code.

 

/500/e?retURL=%2F500%2Fo
&cas4_lkid={!Account.Id}
&cas4={!Account.Name}
&CF00N30000009y6pH_lkid={!Opportunity.Id}
&CF00N30000009y6pH={!Opportunity.Name}
&cas5={!Opportunity.Type}
&cas14={!Opportunity.Name}
&retURL=/{!Opportunity.Id}
&saveURL=/{!Opportunity.Id}

 

I'm guessing the Javascript would need to be structured like this:

 

var status = "{!Opportunity.StageName}";
if (status == "Closed Won")
{
SCRIPT TO CREATE CASE AND POPULATE CASE FIELDS WITH DATA FROM RELATE OPP FIELDS

}
else
{
alert ('Opportunity needs to be won before a case can be created.');
}

 

Can anyone give me any help here?

 

Thanks in advance.

 

Steve

 

Hi All,

 

I have a custom 'create case' button in opportunities that creates a new case from an opportunity, passing some of the opportunity field data across into the case as it does so.

 

The button code looks like this:

 

/500/e?retURL=%2F500%2Fo

&cas4_lkid={!Account.Id}

&cas4={!Account.Name}

&CF00N30000009y6pH_lkid={!Opportunity.Id}

&CF00N30000009y6pH={!Opportunity.Name}

&cas3_lkid={! NULLVALUE (Case.ContactId, Contact.Id )}

&cas3={! NULLVALUE (Case.Contact, Contact.Name )}

&cas5={!Opportunity.Type}

&cas14={!Opportunity.Name}

&cas15={!Opportunity.Requirement__c}

&retURL=/{!Opportunity.Id}

&saveURL=/{!Opportunity.Id}

 

Am I able to disable the function of this custom button if the opportunity stage IS NOT 'closed won'?  Ideally I'd like an alert pop-up box to appear if the 'create case' button is clicked when the opportunity IS NOT 'closed won' but for the button to work as intended and create the new case if the opportunity IS 'closed won'.

 

Any help would be really appreciated.

 

Thanks to all.

 

Steve 

Hi All,

 

We're using PE with Workflow and API enabled.  Until now we've found work-arounds for each PE limitation we've hit, but I'm struggling with this one.

 

We need a case to be automatically created when an opp is closed won.  I'm aware this is quite easily achieved with an Apex trigger in EE, but does anyone know of any work-arounds to achieve it in PE?

 

Thanks in advance.

 

Regards


Steve

Hi All,

 

We're using PE with Workflow and API enabled.  Until now we've found work-arounds for each PE limitation we've hit, but I'm struggling with this one.

 

We need a case to be automatically created when an opp is closed won.  I'm aware this is quite easily achieved with an Apex trigger in EE, but does anyone know of any work-arounds to achieve it in PE?

 

Thanks in advance.

 

Regards


Steve

Hi all,


I've been going round in circles with this for a while now, and could really use a definitive answer if anyone can help.


We use Professional Edition with Workflow and API 'bolted on'.

As a service company we send our customers quotes for installations, repairs, maintenance plans etc.  Each quote we send is logged as an opportunity againt the relevant account.


In our company a case is a job.  Currently when an opportunity is won, we change the opportunity status to 'closed won' and then have to manually open a case for the job that the customer has just accepted.
From time to time staff here update the opp status to 'closed won', but then forget to open a case for the job.  We end up accepting the customer's order, but then not creating a job to fulfil it.


I'd therefore like a case to be automatically created when an opp status is changed to 'closed won'.

 

It seems that this can be achieved with an Apex trigger, but neither our SF Account Executive or Tech Support can tell me whether this is possible with Professional Edition with Workflow and API 'bolted on'.  


Can anyone clarify how we get an Apex trigger into our Org?

Thanks in advance.


Steve

Hi All,

 

We use SF Professional edition with API and Workflow enabled.

 

I've become quite conversant with the administration of our Org since we adopted a year ago, but we now need an Apex trigger to automatically create a case when opportunity status = closed won, and am not really sure how to go about it.

 

Is the trigger something that can be written and added to our Org from the admin setup panel, and if not, please can someone let me know how I get this trigger written and added?

 

Thanks in advance.


Steve

Hi,

We have a custom Javascript button in our opportunity which creates a case and carries some of the opportunity detail across into the case as it does so.

I have a checkbox field in the opportunity and another in the case, and I want the below code to check the checkbox in the new case being created if the checkbox in the opportunity was checked.

I've tried inserting the line in bold below, but this doesn't work.

Can anyone help here?

TIA
Steve


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

var status = "{!Opportunity.StageName}";

if (
"{!Opportunity.Type}" != "Maintenance - New Agreement" &&
"{!Opportunity.Type}" != "Maintenance - Agreement Renewal" &&
"{!Opportunity.Type}" != "Maintenance - Resi MBF"
){

if (status == "Closed Won") {
var caseToCreate = new sforce.SObject("Case");
caseToCreate.AccountId = "{!Opportunity.AccountId}";
caseToCreate.Type = "{!Opportunity.Type}";
caseToCreate.Subject = "{!Opportunity.Name}";
caseToCreate.Origin = "Converted Opportunity";
caseToCreate.Description = "{!Opportunity.Requirement__c}";
caseToCreate.Related_Opportunity__C = "{!Opportunity.Id}";
caseToCreate.ContactId = "{!Opportunity.Opportunity_ContactId__c}";
caseToCreate.RecordTypeId = "01230000001DNJc";
caseToCreate.Case_Value__c = "{!TEXT(Opportunity.Amount)}";
caseToCreate.Case_Parts_Required__c = "{!Opportunity.Opp_Parts_Required__c}";

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

if(result[0].success == "true"){
alert("Case has been created.");
}
else{
alert("Error: " + result[0].errors.message);
}

} else {
alert(
"Opportunity must be won " +
"before a case can be created."
);
}
} else
alert(
"A case cannot be created for maintenance opportunities, " +
"other than ad-hoc maintenance visits. " +
"For maintenance opportunites, please use the " +
"Create Contract button."
);

Hi all,

 

We use the following code behind a custom button that's displayed on our opp detail page to automatically create a case.  We're using Professional Edition, so we don't have Apex available to us for this to happen automatically when the opp stage is changed to closed won.

 

You can see below that we're using an IF statement to only create the case if the opp stage is closed won, and to alert the user if otherwise.

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
   var c = new sforce.SObject("Case");
   c.AccountId = "{!Opportunity.AccountId}";
   c.Type = "{!Opportunity.Type}";
   c.Subject = "{!Opportunity.Name}";
   c.Origin = "Converted Opportunity";
   c.Description = "{!Opportunity.Requirement__c}";
   c.ContactId = "{!Opportunity.Opportunity_ContactId__c}";

   newRecords.push(c);

   result = sforce.connection.create(newRecords);
   alert ('Case has been created.');
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

I need to complicate this further with another IF statement, but not sure how to do so ... here's what we need:

 

We still need the case only to be created if the opp stage = closed won, and to alert the user if otherwise.

 

We have 6 opp types (we'll call them types 1 to 6), and in addition to the above IF statement, we also need the button to create the case if opp type = 1, 2, 3 or 4, but to alert 'A case cannot be created for opportunity types 5 or 6.' (and not create the case) if the opp type = 5 or 6.

 

Can anyone help me with a tweak to my button code to achieve this?

 

Thanks in advance.

 

Steve

Hi all,

 

I've struggled with this for a while and welcome any advice.

 

I want to place a custom button in opportunities (detail page) that, providing the opp stage is 'Closed Won' creates a case, copying a number of opp fields across into the case fields as it does so.

 

I currently have two custom buttons on the page that I'm testing ... both using Onclick Javascript.

 

HERE'S THE CODE BEHIND THE FIRST ONE:

if ("{!Opportunity.StageName}" == 'Closed Won')

{location.href = "/500/e?retURL=%2F500%2Fo

&cas4={!Account.Name}

&cas3={!Opportunity.Opportunity_Contact__c}

&cas5={!Opportunity.Type}

&cas11={!'Converted Opportunity'}

&cas14={!Opportunity.Name}

&cas15={!Opportunity.Requirement__c}

&retURL=/{!Opportunity.Id}&saveURL=/{!Opportunity.Id}";}

else

{alert('Opportunity must be won before a case can be created.'); }

 

What works:

  • The 'new case' page is launched and the fields are populated.

What doesn't work:

  • It doesn't always copy the full content of each field across ... i.e. an opportunity account name of 'ABC Construction Ltd' only populates as 'ABC' in the account name field on the case screen.
  • It requires the user to click the Save button after the fields have been populated.

 

HERE'S THE CODE BEHIND THE SECOND ONE:

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var status = "{!Opportunity.StageName}";
var newRecords = [];

if (status == "Closed Won")
{
var c = new sforce.SObject("Case");
c.AccountId = "{!Opportunity.AccountId}";
c.Contact = "{!Opportunity.Opportunity_Contact__c}";   <-------- Problem arises when other fields are included.
//add any other related fields you like

newRecords.push(c);

result = sforce.connection.create(newRecords);
}
else
{
alert ('Opportunity must be won before a case can be created.');
}

 

What works:

  • Providing the line in red is left out, the button works fine.

What doesn't work:

  • As soon as I try to include any additional fields to carry across from the opp to the case, the button no longer works ... no case is created at all.

 

Can anyone tell me which code is best, or provide some guidance as to how to tweak either of the existing codes so that they work in the way I'd like them to?

 

Sorry for the long post!

 

Regards


Steve

 

Hi all,

 

We use web-to-lead, which generates lots of enquiries from outside of our area of coverage (despite our area of coverage being clearly stipulated on all of our contact pages!).

 

Out of courtesy, before deleting a lead who's outside of our area, I'd like a button (in Leads) that sends them a templated email saying 'Thanks for your enquiry but sorry, you are outside of our coverage area (blah blah)'.

 

I'm fine with creating custom buttons, but could use some code to create and send the email.  Ideally the email will contain a couple of lead mergefields and be created and sent on a single click (I don't need to review it).

 

I'm conversant with creating email templates.

 

Can anyone give me some guidance as to the best button code to pull this action together please?

 

Thanks in advance.


Steve

 

PS:  It would be even better if the button could email the lead and then delete them?

Hi All,

 

I'm hoping that someone can help me with this?

 

I want to create a custom button in Opps that creates a new case, providing the Opp is 'closed won'.

If the Opp is not 'closed won', then I need it to alert "Opp must be won to create case".

 

I've created a button using 'Content Source = URL' which creates a new case and populates the new case fields with data from the related Opp fields (see code below), but now that I want this to be conditional on the related Opp being closed won, it seems I need to make the button OnClick Javascript and use some Javascript code.

 

/500/e?retURL=%2F500%2Fo
&cas4_lkid={!Account.Id}
&cas4={!Account.Name}
&CF00N30000009y6pH_lkid={!Opportunity.Id}
&CF00N30000009y6pH={!Opportunity.Name}
&cas5={!Opportunity.Type}
&cas14={!Opportunity.Name}
&retURL=/{!Opportunity.Id}
&saveURL=/{!Opportunity.Id}

 

I'm guessing the Javascript would need to be structured like this:

 

var status = "{!Opportunity.StageName}";
if (status == "Closed Won")
{
SCRIPT TO CREATE CASE AND POPULATE CASE FIELDS WITH DATA FROM RELATE OPP FIELDS

}
else
{
alert ('Opportunity needs to be won before a case can be created.');
}

 

Can anyone give me any help here?

 

Thanks in advance.

 

Steve

 

Hi All,

 

I have a custom 'create case' button in opportunities that creates a new case from an opportunity, passing some of the opportunity field data across into the case as it does so.

 

The button code looks like this:

 

/500/e?retURL=%2F500%2Fo

&cas4_lkid={!Account.Id}

&cas4={!Account.Name}

&CF00N30000009y6pH_lkid={!Opportunity.Id}

&CF00N30000009y6pH={!Opportunity.Name}

&cas3_lkid={! NULLVALUE (Case.ContactId, Contact.Id )}

&cas3={! NULLVALUE (Case.Contact, Contact.Name )}

&cas5={!Opportunity.Type}

&cas14={!Opportunity.Name}

&cas15={!Opportunity.Requirement__c}

&retURL=/{!Opportunity.Id}

&saveURL=/{!Opportunity.Id}

 

Am I able to disable the function of this custom button if the opportunity stage IS NOT 'closed won'?  Ideally I'd like an alert pop-up box to appear if the 'create case' button is clicked when the opportunity IS NOT 'closed won' but for the button to work as intended and create the new case if the opportunity IS 'closed won'.

 

Any help would be really appreciated.

 

Thanks to all.

 

Steve 

Hi All,

 

We're using PE with Workflow and API enabled.  Until now we've found work-arounds for each PE limitation we've hit, but I'm struggling with this one.

 

We need a case to be automatically created when an opp is closed won.  I'm aware this is quite easily achieved with an Apex trigger in EE, but does anyone know of any work-arounds to achieve it in PE?

 

Thanks in advance.

 

Regards


Steve

Hi All,

 

We use SF Professional edition with API and Workflow enabled.

 

I've become quite conversant with the administration of our Org since we adopted a year ago, but we now need an Apex trigger to automatically create a case when opportunity status = closed won, and am not really sure how to go about it.

 

Is the trigger something that can be written and added to our Org from the admin setup panel, and if not, please can someone let me know how I get this trigger written and added?

 

Thanks in advance.


Steve