Skip to main content
Hi,

 

I am getting stuck as new to Java coding

 

I have a custom object called User_Story__c and another called Vote__c (child object as related list)

 

I want to be able to click a button on the user story object and this populates the related list Vote__c with the name of that user.  So far I have a page list button on the user story object with: -

 

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

 

 

 

var newvote = new sforce.SObject('Votes__c');

 

newvote.Voted__c = {!User.IsActive};

 

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

 

 

 

if(result[0].success == 'true'){

 

    alert('Thanks for Voting!.');

 

}

 

Does anyone know what I am missing as nothing happens when the button is clicked.  Do I need to input the ID number as well or am I miles away?

 

Thanks

 

Nick

 

 
7 answers
  1. Jun 29, 2015, 3:00 PM

    All right Nick. That helped. Here you go:

    {!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

    var voteObj = new sforce.SObject("Vote__c");

    voteObj.User_Story_ID__c = '{!User_Story__c.Id}';

    voteObj.User_Lookup__c = sforce.connection.getUserInfo().userId;

    var result = sforce.connection.create([voteObj]);

    if (result[0].success=='false') {

    alert(result[0].errors.message);

    } else {

    location.reload(true);

    }

     

    Just copy paste the above. Make sure you change the bolded field names to be the field names in your org (on the Vote object), since I just made an assumption.
0/9000