You need to sign in to do that
Don't have an account?
Robert Zentgraf
Javascript to create and update record
Hi,
I created a button with JS-code. In this code, I create a new record (custom object A__c) and update the currect record (object Contact). On both objects I have a look-up-field to the other object. On the new record (object A__c), I can create the connection to the current record, in the current record (object Contact), I can't assign the new record (object A__c).
Can you please help me?
Regards
Robert
I created a button with JS-code. In this code, I create a new record (custom object A__c) and update the currect record (object Contact). On both objects I have a look-up-field to the other object. On the new record (object A__c), I can create the connection to the current record, in the current record (object Contact), I can't assign the new record (object A__c).
Can you please help me?
Regards
Robert
1. share your code, it will help to resolve your problem
2. which object you have created this Button
3. relationship between A__c and Contact
here the code:
var B_Contact = new sforce.SObject("Contact");
var B_A__c = new sforce.SObject("A__c");
B_Contact.Id = "{!Contact.Id}";
B_Contact.Sourcing__c = "DONE"
B_A__c.Contact_Active_Sourcing__c = "{!Contact.Id}";
result = sforce.connection.create([B_A__c]);
var Id = sforce.connection.query("SELECT Id FROM A__c WHERE Contact_Active_Sourcing__c = '{!Contact.Id}'");
B_Contact.LookUpTo_A__c = Id;
result = sforce.connection.update([B_Contact]);
Regards
Robert
Replace var Id to var contactId
So your code will be
var contactId= sforce.connection.query("SELECT Id FROM A__c WHERE Contact_Active_Sourcing__c = '{!Contact.Id}'");
B_Contact.LookUpTo_A__c = contactId;
Let me know the error message if it still does not work.