1

I created a Java Button that should create a Record on Object Zeiteintrag__c on this record is a Master Detail Relationship (Stundenkonto__c) that should be Updated with the ID of the Record of this month (Stundenkonto__c).

I always get the error:

missing ) after argument list

I think the second var is the problem. Could anybody help out?

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

// query the record
var qr= sforce.connection.query("SELECT Id, Start__c, Ende__c FROM Zeiteintrag__c WHERE CreatedById='" + "{!$User.Id}" + "' AND Start__c=TODAY AND RecordTypeId="0123E0000008U9J" limit 1");

records = qr.getArray("records");

var te = records[0];

var qs= sforce.connection.query("SELECT Id FROM Stundenkonto__c WHERE OwnerId='" + "{!$User.Id}" + "' AND Monat__c={!MONTH(TODAY())} limit 1");

var rcds = qs.getArray("records");

if (te==null)
{

  var te = new sforce.SObject("Zeiteintrag__c");

  te.Start__c = new Date();

  **te.Stundenkonto__c = rcds[0].Id;**

  // insert new te
  result = sforce.connection.create([te]);

  if(result[0].success == 'true')
  {
    alert('Ein neuer Zeiteintrag ' + result[0].id+ ' wurde erstellt.');
  }
}
else
{
 if(te.Ende__c==null)
 {  
  te.Ende__c = new Date();

  //update te
  result = sforce.connection.update([te]);

  if(result[0].success == 'true')
  {
    alert('Der Zeiteintrag '+ result[0].id + ' wurde abgeschlossen.');
  }
 }
 else
 {
 alert('Heute wurde bereits ein Zeiteintrag erstellt und abgeschlossen. Bitte wenden Sie sich an Ihren Systemadministrator.');
 }
}

1 Answer 1

2

The problem is this line:

var qr= sforce.connection.query("SELECT Id, Start__c, Ende__c FROM Zeiteintrag__c WHERE CreatedById='" + "{!$User.Id}" + "' AND Start__c=TODAY AND RecordTypeId="0123E0000008U9J" limit 1"); 

You haven't properly escaped your quotation marks. You just need to change the code a bit:

var qr= sforce.connection.query("SELECT Id, Start__c, Ende__c FROM Zeiteintrag__c WHERE CreatedById=\"{!$User.Id}\" AND Start__c=TODAY AND RecordTypeId=\"0123E0000008U9J\" limit 1"); 
1
  • Thank you for your help. now i got the next problem. Unexpected identifier Jun 6, 2016 at 6:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .