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
LauraJMLauraJM 

Custom Button - passing parameters - What am I doing wrong?

a1O/e?
CF00NC00000052E9C={!Quote.Name}&
CF00NC00000052E9C={!Quote.Id}&
CF00NC00000052E4q={!QuoteLineItem.LineNumber}&
CF00NC00000052E4q={!QuoteLineItem.Id}&
CF00NC00000052E68={!Quote.End_User__c}&
CF00NC00000052E68={!Quote.End_UserId__c}&
save=x

This is my custom button, but only the Quote Line Item lookup is populating.  I am stumped as to what I am doing wrong.  

Clarification (14 minutes ago)

 

Right, it's a little tedious to do each one, I won't neccessarily need a custom object on every line item within a quote.  That's why I thought this button would do the trick and enough information could be pre-populated then it would lessen the tedious work. 

I changed the a1O/e? to /a1O/e?retURL={!QuoteLineItem.Id}& but it didn't make a difference. 

Would it matter that the look up on the quote line item is Master-Detail and on the Custom object is just a lookup?  That's the only difference I can find between my Contact-Account/Custom Object example and this current example.

Clarification (28 minutes ago)

 

But the quote line item has the Quote lookup on it's record (it's a Master-Detail).  So the last situtation where I did this was on a Contact record, I am pulling Contact and Account fields and lookup to a custom object.  Isn't that the same thing?

Clarification (50 minutes ago)

 

Of course, sorry about that!  We use the out-of-the-box quotes and quote line items that Salesforce provides.  I have created a custom object that I want to create off of the quote line item record.  So this custom button resides within the Quote Line Item object.  In my custom object, I have three lookups - Account, Quote & Quote Line Item.  All three of these lookups are also either on the Quote Line Item or Quote page, so I thought I could pull them through easy. I thought I had done something similar to this recently on a different object.

HELP!

 

MikeGillMikeGill

Q. Are you trying to prefil fields in this custom object using a custom button?

LauraJMLauraJM

Yes I would like to prepopulate my fields in the custom object.  I have three lookup fields on the custom object that match to the quote and quote line items lookups and I want to pull in that information and populate the fields.  The only one I have working is the quote line item lookup.

MikeGillMikeGill

Ok I understand. It may be easier to use apex here. Yes I thinked it not possible to pull information through which is not directly related.

 

What version of SFDC are you using?

LauraJMLauraJM

The problem is I'm more of a button-click developer/admin :).  I want to learn the Apex, but that will take me a few months and I need a solution today.  

 

I did something similar with a Contact record, where I put a button on the Contact record, and when the button is clicked it creates a new custom object record which populates with Contact and Account data.  Why is it working for me in that situation but not in this one/

 

Does it make a difference that the Quote to Quote Line Item relationship is Master-Detail where as the Contact to Account is not?

LauraJMLauraJM

Oh ... to your question, we are on Enterprise.  Is that what you were asking?

MikeGillMikeGill

Just setting this up in dev

 

Custom Object with Master-detail > Quote?

MikeGillMikeGill

ignore that - I see from a previous post

LauraJMLauraJM

My custom object does not have any Master Detail relationships, although I could probably change that if necessary. 

 

I can't get any other parameters to pass other than the quote line item look up.  I tried to pass a formula text field into the Record Name and it's not working either. 

MikeGillMikeGill

Can you post your button code please

LauraJMLauraJM

This is my original code:

a1O/e?
CF00NC00000052E9C={!Quote.Name}&
CF00NC00000052E9C={!Quote.Id}&
CF00NC00000052E4q={!QuoteLineItem.LineNumber}&
CF00NC00000052E4q={!QuoteLineItem.Id}&
CF00NC00000052E68={!Quote.End_User__c}&
CF00NC00000052E68={!Quote.End_UserId__c}&
save=x


 

Line 2 & 3 was supposed to fill in the Quote Lookup, line 4 & 5 was supposed to fill in the Quote Line Item lookup (this works) and line 6 & 7 was supposed to fill in the Account lookup, which is only available on the Quote page which may be part of my problem.  But again my Account-Contact example worked, so it seems like I should be able to at least fill in the Quote and Quote Line Item lookup. 

MikeGillMikeGill

Still here- just playing with this to work within your use case

 

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js" )}
{!REQUIRESCRIPT("/soap/ajax/16.0/apex.js" )}
var t1= new sforce.SObject("Task" ); 
t1.OwnerId = "005900000018PVr";//SFDC ID of user record
t1.Subject = "ABC"; 
t1.Status = "Not Started"; 
t1.Priority = "Normal";
result = sforce.connection.create([t1]);
alert(result );//You may remove this alert before deployment

 

LauraJMLauraJM

I hate to be completely ignorant, but can you explain what you posted to me? 

 

I am still working from several different angles on my end for this too, but utilizing the "new custom button" section and trying to pass parameters, nothing is working. 

CodeFinderCodeFinder

Hey laura, We worked on this issue before. I have a sample of a code we worked on before. use this.

 

retURL=/{!Account.Id}
/a06/e?CF00N30000007eLJc={!Account.Name}&CF00N30000007eLJc_lkid={!Account.Id}&
00N30000007eKjn={!Account.Calle_facturacion__c}&
00N30000007eKjs={!Account.Ciudad_Facturacion__c}&
CF00N30000007eKkH={!Account.Pais_facturacion__c}&
CF00N30000007eKkH_lkid={!Account.Pais_facturacionId__c}&
CF00N30000007eKkM={!Account.Estado_Provincia_facturacion__c}&
CF00N30000007eKkM_lkid={!Account.Estado_Provincia_facturacionId__c}&
00N30000007eKkR={!Account.Codigo_Postal_facturacion__c}&
retURL=/{!Account.Id}
 
 

 
Need to put CF before any look up field & for the _lkid need to use the look up ID field. :))))

 

For more info you can check this post. 

 

http://boards.developerforce.com/t5/General-Development/custom-button-look-up-issues/m-p/312131/highlight/false#M58098

 

Let me know if this helps.

MikeGillMikeGill

Ok, this works for me. (You will need your field names)

 

You still need to add Account into the mix. 

 

Create the button in the normal way

 

With Behavior = Execute Javascript

Content Source = JavaScript

 

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

var result = sforce.connection.query("SELECT Id,  QuoteId FROM QuoteLineItem WHERE Id='{!QuoteLineItem.Id}'");

var records = result.getArray("records");

 for (var i=0; i< records.length; i++) {
    var record = records[i];
     var QuoteLineId = record.Id;
     var QuoteId = record.QuoteId;
  }

   alert("QuoteId="+QuoteId);
   alert("QuoteLineId="+QuoteLineId);

   var qd = new sforce.SObject("CA__Quote_Details__c" ); 
    qd.CA__Quote__c = QuoteId;
    qd. CA__Quote_Line_Item__c = QuoteLineId
    var success = sforce.connection.create([qd]);
   alert (success);

 

Sorry it took so long, I have never done this before. Actually very flexible. I think you should be able to traverse master-detail relationships...

 

M

 

LauraJMLauraJM

Wow, thank you for spending so much time on this.  Will you walk me through it a little bit?

 

Would this be where I would change your code to reflect my custom object?

  var qd = new sforce.SObject("CA__Quote_Details__c" );
    qd.CA__Quote__c = QuoteId;
    qd. CA__Quote_Line_Item__c = QuoteLineId

MikeGillMikeGill
Yep put your correct custom object name and fields...

BTW - the quote is nasty, no natural link to account from it (could be me)

Anyway the up shot is if you can get everything you need onto the object where the button is, then you can query the values and populate your custom object.
LauraJMLauraJM

I can live without the Account lookup if I can get the quote AND quote line item lookup working.  I'll try this is just a bit and see if I can get it working with my changes.  Thanks again so much!  I need a Java coach to live in my office until I can learn these things :)

MikeGillMikeGill
Good luck, don't forget to drop the alerts
babrannobabranno

This works great for creating a task but can it be modified to actually open the window to record the task rather than creating an open task. I have tried creating the url with the related to prepopulated with a custom object id and I keep getting an error that the url no longer exists. It works fine with your script to create the open activity, but for some reason if I just try to create the url I get nowhere and it is driving me crazy. I would appreciate any help.

MikeGillMikeGill
// Call AJAX Api
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js" )}

// Create sObject for Task
var fu = new sforce.SObject("Task" ); 

// Set a couple of fields
fu.WhatId = '{!Account.Id}';
fu.Subject = 'Follow-up with Account';

// Create the task
var success = sforce.connection.create([fu]);
var taskId = success[0].id;
window.location = "/"+taskId;

 

This is half way, it creates the tasks and then redirects you to that task.

 

I'm guessing you probably want to redirect to a new task record?

 

 

babrannobabranno

This is good enough.

 

Ideally it would just open the page in a simlar way that the "Log a Call" Button does but just prepopulates the fields I need it to.

 

Thanks for your help.

LauraJMLauraJM

Create the following new custom buttons under Task Buttons & Links. 

 

for Account records:

/00T/e?title=Phone Call&what_id={!Account.Id}&followup=1&tsk5=Phone Call&retURL=%2F{!Account.Id}

 

for Contact records:

/00T/e?who_id={!Contact.Id}&followup=1&tsk5=Phone Call&retURL=%2F{!Contact.Id}

 

Then you should be able to add more parameters that you want to pass through with an "&"